我在Windows 7 64位上使用Python 3.5 64位,shapely版本为1.5.13。
以下是我的代码,返回了一个自相交的多边形:
import numpy as np
from shapely.geometry import Polygon, MultiPolygon
import matplotlib.pyplot as plt
x = np.array([ 0.38517325, 0.40859912, 0.43296919, 0.4583215 , 0.4583215 ,
0.43296919, 0.40859912, 0.38517325, 0.36265506, 0.34100929])
y = np.array([ 62.5 , 56.17977528, 39.39698492, 0. ,
0. , 17.34605377, 39.13341671, 60.4180932 ,
76.02574417, 85.47008547])
polygon = Polygon(np.c_[x, y])
plt.plot(*polygon.exterior.xy)
这是正确的。然后我尝试使用buffer(0)
方法来获取两个单独的多边形:
split_polygon = polygon.buffer(0)
plt.plot(*polygon.exterior.xy)
print(type(split_polygon))
plt.fill(*split_polygon.exterior.xy)
很遗憾,它只返回了两个多边形中的一个:
请问有人可以帮忙吗?谢谢!
shapely.validation.make_valid(shapely.geometry.Polygon(np.c_[x, y]))
一行代码来获取相同的多边形。 - RunOrVeith