如何从Shapely多边形切割x
和y
坐标?
我得到以下输出:
[evaluate xyz_25_2.py]
POLYGON ((3.449182842266765 -5.876385583121159, 2.171707715501299 -3.576930354943315, 0.6387375633827332 -1.447805143667534, -3.875007884521928 6.046715600023223, -6.004133095797705 7.750015769043845, -9.581063450741024 ..........................))
Traceback (most recent call last):
File "C:\Users\abhi\Desktop\xyz_25_2.py", line 103, in <module>
list(concave_hull)
TypeError: 'Polygon' object is not iterable
答案 0 :(得分:1)
您需要检索外部或内部线性环并将它们送入numpy。然后,您可以轻松切割坐标。
例如:
from shapely import geometry
import numpy as np
# lets create an example polygon
p = geometry.Point(0,0)
poly = p.buffer(100)
# you need to get the coordinates of the exterior (shell)
# pass these into a numpy array
shell_coords = np.array(poly.exterior)
print(shell_coords)
# you can do the same for interior (holes) as well
# then slice and dice to your heart's content
print(shell_coords[:,:1])
print(shell_coords[:,1:2])