gpt4 book ai didi

python - 如何从 Shapely 多边形中切出 x 和 y 坐标? [类型错误: 'Polygon' object is not iterable]

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:33 25 4
gpt4 key购买 nike

如何切片 xy来自 Shapely 多边形的坐标?

我得到以下输出:

[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

最佳答案

您需要检索外部或内部线性环并将其输入 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])

关于python - 如何从 Shapely 多边形中切出 x 和 y 坐标? [类型错误: 'Polygon' object is not iterable],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com