如何从Shapely多边形切片x和y坐标? [TypeError:“多边形”对象不可迭代] [英] How can I slice x and y coordinates from a Shapely polygon? [TypeError: 'Polygon' object is not iterable]

查看:359
本文介绍了如何从Shapely多边形切片x和y坐标? [TypeError:“多边形”对象不可迭代]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Shapely多边形中切片 x y 坐标?

How can I slice x and y coordinates from a Shapely polygon?

我得到以下输出:

[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。然后,您可以轻松地分割坐标。

You need to retrieve the exterior or interior Linear Ring and feed these into numpy. You can then easily slice the coords.

例如:

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])

这篇关于如何从Shapely多边形切片x和y坐标? [TypeError:“多边形”对象不可迭代]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆