Skip to content

Commit 7336a8a

Browse files
committed
Use a 0.005m tolerance when dissolving polygons (requires QGIS 3.42)
Avoids small slivers showing when meshblocks don't exactly align
1 parent 78d7fd8 commit 7336a8a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

redistrict/core/core_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ def union_geometries(geometries: List[QgsGeometry]) -> QgsGeometry:
5151
"""
5252
Unions geometries, using the optimal method available
5353
"""
54-
if Qgis.QGIS_VERSION_INT >= 33600:
54+
if Qgis.QGIS_VERSION_INT >= 34100:
55+
# use optimized GEOS coverage union method
56+
# this is only possible for polygons, which should be safe to
57+
# assume, unless we are running the test suite!
58+
if all(g.type() == QgsWkbTypes.PolygonGeometry for g in
59+
geometries):
60+
collected_multi_polygon = QgsGeometry.collectGeometry(geometries)
61+
# use low-level API so that we can specify a 0.005m tolerance, to avoid
62+
# slivers
63+
geos_engine = QgsGeometry.createGeometryEngine(collected_multi_polygon.constGet(), 0.005)
64+
geom, err = geos_engine.unionCoverage()
65+
return QgsGeometry(geom)
66+
elif Qgis.QGIS_VERSION_INT >= 33600:
5567
# use optimized GEOS coverage union method
5668
# this is only possible for polygons, which should be safe to
5769
# assume, unless we are running the test suite!

0 commit comments

Comments
 (0)