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

标签 python debugging shapely

如何切片 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/

相关文章:

python - 如何以匀称的方式(或更好的库)创建带弧的多边形

python - PyCharm 警告 : Unexpected type for filter on dictionary

python - 按街道地址分组并将其拆分为街道名称和号码

python - 为什么在 python 线程中监视键盘中断不起作用

python - 如何查看 Python 应用程序发送的整个 HTTP 请求?

python - 文件 .gdbinit 的含义是什么?

asp.net-mvc - 如何在启动应用程序之前在 system.web.mvc 中放置断点?

python - 属性错误: 'LGEOS360' object has no attribute 'GEOSBufferWithParams'

Python:距离直线最近的点

python - 从 python/postgresql/psycopg2 中的用户输入安全地指定 'order by' 子句