2016-06-08 78 views
1

Attached image shows the LineString or rather LineRing and a polygon. I expect them to intersect but they don not as per shapely intersects我有兩個我期望相交的幾何圖形。但他們沒有。一個是線串(形成一個環)和另一個完全在線串內的小方形多邊形。它不會觸及任何線路點。 看着千篇一律的交叉路口文件,我期望他們相交,但他們不; t。形狀幾何相交 - 在哪些情況下線串和多邊形會相交?

geom1 = LINESTRING (-68.41186519999999 -19.429039, -68.35556029999999 -19.5293773, -68.24775699999999 -19.5717596, -68.1444168 -19.6110584, -68.0488014 -19.5375473, -67.87353520000001 -19.5287301, -67.75165560000001 -19.4610893, -67.67972949999999 -19.4220778, -67.7508831 -19.389615, -67.9814672 -19.3241436, -68.0075276 -19.2455493, -67.9786563 -19.1669174, -68.0376756 -19.0532041, -68.10563740000001 -19.1637403, -68.14785809999999 -19.1696967, -68.1900787 -19.1185707, -68.25668330000001 -19.1775984, -68.3349609 -19.1970534, -68.3638 -19.2152094, -68.4386444 -19.2709616, -68.44757079999999 -19.3370618, -68.41186519999999 -19.429039) 

Geom2 = tile_polygon_geom = MULTIPOLYGON (((-68.203125 -19.331878, -68.203125 -19.352611, -68.181152 -19.352611, -68.181152 -19.331878, -68.203125 -19.331878))) 

如果我編輯LINESTRING爲多邊形 - 保持積分相同,只是改變了測試LINESTRING多邊形我看到的外部和內部多邊形相交。

("POLYGON((-68.41186519999999 -19.429039, -68.35556029999999 -19.5293773, -68.24775699999999 -19.5717596, -68.1444168 -19.6110584, -68.0488014 -19.5375473, -67.87353520000001 -19.5287301, -67.75165560000001 -19.4610893, -67.67972949999999 -19.4220778, -67.7508831 -19.389615, -67.9814672 -19.3241436, -68.0075276 -19.2455493, -67.9786563 -19.1669174, -68.0376756 -19.0532041, -68.10563740000001 -19.1637403, -68.14785809999999 -19.1696967, -68.1900787 -19.1185707, -68.25668330000001 -19.1775984, -68.3349609 -19.1970534, -68.3638 -19.2152094, -68.4386444 -19.2709616, -68.44757079999999 -19.3370618, -68.41186519999999 -19.429039))」) 

即代碼下面的代碼輸出「幾何形狀相交」

geometry1 = wktloads ("POLYGON((-68.41186519999999 -19.429039, -68.35556029999999 -19.5293773, -68.24775699999999 -19.5717596, -68.1444168 -19.6110584, -68.0488014 -19.5375473, -67.87353520000001 -19.5287301, -67.75165560000001 -19.4610893, -67.67972949999999 -19.4220778, -67.7508831 -19.389615, -67.9814672 -19.3241436, -68.0075276 -19.2455493, -67.9786563 -19.1669174, -68.0376756 -19.0532041, -68.10563740000001 -19.1637403, -68.14785809999999 -19.1696967, -68.1900787 -19.1185707, -68.25668330000001 -19.1775984, -68.3349609 -19.1970534, -68.3638 -19.2152094, -68.4386444 -19.2709616, -68.44757079999999 -19.3370618, -68.41186519999999 -19.429039))」) 

gepmetry2 = wktloads ("MULTIPOLYGON (((-68.203125 -19.331878, -68.203125 -19.352611, -68.181152 -19.352611, -68.181152 -19.331878, -68.203125 -19.331878)))") 

if geometry1.intersects(gepmetry2): 
    self.logger.info("geometries intersect") 
else: 
    self.logger.info("geometries do not intersect") 

有人可以解釋什麼是LINESTRING的交叉點和多邊形中,如果: 1)多邊形線和在所述線串橫一些點 2)多邊形包含在一個線串內,沒有點觸摸 3)線串完全封閉在多邊形內,沒有點觸

正如我所提到的,我期待#2迴歸真實,但它沒有。

文檔我指的是:http://toblerity.org/shapely/manual.html

object.intersects(其他)​​ 返回true如果對象的邊界和內飾與那些任何方式相交另一個。

此謂詞等同於contains(),crosses(),equals(),touches()和within()中的OR-ing。

謝謝!

回答

0

geom1Geom2不是有效地構造的幾何形狀。

如果你調整你的代碼類似於你用geometry1gepmetry2的辦法,那麼它會工作:

from shapely import geometry, wkt 

linestring = wkt.loads ("LINESTRING(-68.41186519999999 -19.429039, -68.35556029999999 -19.5293773, -68.24775699999999 -19.5717596, -68.1444168 -19.6110584, -68.0488014 -19.5375473, -67.87353520000001 -19.5287301, -67.75165560000001 -19.4610893, -67.67972949999999 -19.4220778, -67.7508831 -19.389615, -67.9814672 -19.3241436, -68.0075276 -19.2455493, -67.9786563 -19.1669174, -68.0376756 -19.0532041, -68.10563740000001 -19.1637403, -68.14785809999999 -19.1696967, -68.1900787 -19.1185707, -68.25668330000001 -19.1775984, -68.3349609 -19.1970534, -68.3638 -19.2152094, -68.4386444 -19.2709616, -68.44757079999999 -19.3370618, -68.41186519999999 -19.429039)") 

poly1 = wkt.loads ("POLYGON((-68.41186519999999 -19.429039, -68.35556029999999 -19.5293773, -68.24775699999999 -19.5717596, -68.1444168 -19.6110584, -68.0488014 -19.5375473, -67.87353520000001 -19.5287301, -67.75165560000001 -19.4610893, -67.67972949999999 -19.4220778, -67.7508831 -19.389615, -67.9814672 -19.3241436, -68.0075276 -19.2455493, -67.9786563 -19.1669174, -68.0376756 -19.0532041, -68.10563740000001 -19.1637403, -68.14785809999999 -19.1696967, -68.1900787 -19.1185707, -68.25668330000001 -19.1775984, -68.3349609 -19.1970534, -68.3638 -19.2152094, -68.4386444 -19.2709616, -68.44757079999999 -19.3370618, -68.41186519999999 -19.429039))") 

if poly1.intersects(linestring): 
    print("linestring intersects") 
else: 
    print("linestring does not intersect") 

poly2 = wkt.loads ("MULTIPOLYGON (((-68.203125 -19.331878, -68.203125 
-19.352611, -68.181152 -19.352611, -68.181152 -19.331878, -68.203125 -19.331878)))") 

if poly1.intersects(poly2): 
    print("polys intersect") 
else: 
    print("polys do not intersect")