2016-02-26 63 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

那麼..它的工作..謝謝.. –