aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2024-09-19 18:36:04 +0200
committerGuilhem Moulin <guilhem@fripost.org>2024-09-19 18:39:35 +0200
commit287ee168d9879433e356acada20400e63cd9683c (patch)
treede24108a21c7183ec5189f22dff9475524979c9f
parente487f029eb68f7b48de19c82fe0f7ccf5e512a81 (diff)
MRR: Relax triangulation() to avoid failing in some degenerate cases.
In some degenerate cases DelaunayTriangulation() returns a GEOMETRYCOLLECTION where no triangle is fully contained in the input geometry, which causes getRandomPoint() to fail as the list of cumulative weights is an empty list. We “overshoot” in that case and return the non-curated triangulation. getRandomPoint(…, max_tries=1024) should be enough to eventually hit a point in the input geometry.
-rw-r--r--webmap-download-mrr.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/webmap-download-mrr.py b/webmap-download-mrr.py
index 2477f8a..f839ac0 100644
--- a/webmap-download-mrr.py
+++ b/webmap-download-mrr.py
@@ -422,7 +422,11 @@ def triangulate(geom):
triangle = triangulation.GetGeometryRef(i)
if geom.Contains(triangle):
triangulation2.AddGeometry(triangle)
- return triangulation2
+ if triangulation2.IsEmpty():
+ # can happen in some degenerate cases
+ return triangulation
+ else:
+ return triangulation2
# Return the centroid (modulo rounding) if is within the input geometry,
# and None, None otherwise