多边形间的OGR求交方法

2024-07-03 07:31:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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

Tags: none多边形returnsgeometrypolygonogrintersectionpolya