【问题标题】:OGR Intersection method between polygons returning None返回 None 的多边形之间的 OGR 交集方法
【发布时间】:2019-08-07 11:53:41
【问题描述】:

我正在尝试使用 python OGR 库获取两个多边形的相交几何结果。

我已经验证了每个多边形都是一个几何图形并且它们相交。但是,intersects 返回 true,而 Intersection 返回 None。有什么想法吗?

# First polygon
ringA = ogr.Geometry(ogr.wkbLinearRing)
ringA.AddPoint(1179091.1646903288, 712782.8838459781)
...
polyA = ogr.Geometry(ogr.wkbPolygon)
polyA.AddGeometry(ringA)

# Second polygon
ringB = ogr.Geometry(ogr.wkbLinearRing)
ringB.AddPoint(1179091.1646903288, 712782.8838459781)
...
polyB = ogr.Geometry(ogr.wkbPolygon)
polyB.AddGeometry(ringB)

if (polyA.Intersects(polyB)) # returns True
    return polyA.Intersection(polyB) # returns None

【问题讨论】:

    标签: python geometry intersection ogr


    【解决方案1】:

    我遇到了类似的问题。根据Enabling GEOS for GDAL/OGRdocumentation,没有GEOS,只比较两个几何的包络。如果不从源代码编译 GDAL,我无法找到如何启用 GEOS(在 Ubuntu 18.04 中,欢迎任何帮助!)。

    但是,作为一种解决方法,我建议

        intersect_geom = polyA.Intersection(polyB)
        if(intersect_geom is not None and intersect_geom.Area()>0):
            return intersect_geom
    

    在我的例子中,intersect_geom 在大多数几何不相交的情况下是 None。然而,在某些情况下,intersect_geomGEOMETRYCOLLECTION EMPTY,我通过Area()>0 进行检查。

    我希望这会有所帮助,即使问题已经存在 6 个月了。

    【讨论】:

      猜你喜欢
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多