2016-02-26 61 views
0

如何从一个Shapely多边形切片xy坐标?如何从一个Shapely多边形切片x和y坐标? [TypeError:'多边形'对象是不可迭代的]

我得到以下输出:

[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 
+1

欢迎堆栈溢出!我编辑了你的问题的标题,把实际的问题放在第一位,然后再输入错误信息。我也猜到了你'这个'的含义,并在问题主体中重复了这个问题。我猜你以前的问题主体是你看到的输出,所以我将它标记为没有语法突出显示的代码块。请[编辑您的问题](http://stackoverflow.com/posts/35651620/ed)包含导致该错误的代码的相关部分。 –

回答

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

这些是我已经计算凹点的点..这些点后,我执行cascaded_union(edge_points)..我只是想从这个对象中提取点..当我尝试我只是结果非可迭代对象 –

+0

有些你回答对我有帮助..虽然我只是想把x和y的值加入到不同的列表中......就像x = [所有的x值],y = [所有的y值] –

+0

那么..它的工作..谢谢.. –