【问题标题】:Shapely geometry intersection - in which cases a line string and polygon would intersect?匀称的几何相交 - 在哪种情况下,线串和多边形会相交?
【发布时间】:2016-06-08 17:37:45
【问题描述】:

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,我就会看到外部和内部多边形相交。

("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。

谢谢!

【问题讨论】:

    标签: shapely


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-01-19
      • 2013-10-16
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 2019-05-31
      • 2014-07-28
      • 2015-09-21
      相关资源
      最近更新 更多