From 287ee168d9879433e356acada20400e63cd9683c Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 19 Sep 2024 18:36:04 +0200 Subject: MRR: Relax triangulation() to avoid failing in some degenerate cases. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- webmap-download-mrr.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'webmap-download-mrr.py') 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 -- cgit v1.2.3