Attached image shows the LineString or rather LineRing and a polygon. I expect them to intersect but they don not as per shapely intersects我有两个几何形状,我希望它们相交。但他们没有。一个是线串(形成一个环)和另一个完全在线串内的小方形多边形。它不会触及任何线串点。 看着匀称的交叉口文件,我希望它们相交,但它们不会。
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即可看到外部和内部多边形相交。
("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返回true,但事实并非如此。
我指的文档:http://toblerity.org/shapely/manual.html
object.intersects(其他) 如果对象的边界和内部以任何方式与另一个的边界和内部相交,则返回True。
这个谓词相当于contains(),crosses(),equals(),touches()和within()的OR-ing。
谢谢!
答案 0 :(得分:0)
geom1
和Geom2
不是有效构造的匀称几何体。
如果您将代码调整为类似于geometry1
和gepmetry2
所使用的方法,那么它将起作用:
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")