From 64cbe4397cde0187a714814d33f1e878280da2b8 Mon Sep 17 00:00:00 2001 From: Andrew Kirmse Date: Thu, 3 Oct 2024 21:48:09 -0700 Subject: [PATCH] Work around case of invalid boundary. Extremely rarely, data with holes can result in invalid geometry. Force it to be valid. --- scripts/boundary.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/boundary.py b/scripts/boundary.py index ce764cd..ecd2ae9 100644 --- a/scripts/boundary.py +++ b/scripts/boundary.py @@ -47,9 +47,13 @@ def add_dataset(self, filename): overview_level = None if footprint: - geometry = footprint.GetLayer(0).GetNextFeature() - if geometry: # Tiles can be completely empty - self.batch_boundary = self.batch_boundary.Union(geometry.geometry()) + feature = footprint.GetLayer(0).GetNextFeature() + if feature: # Tiles can be completely empty + geometry = feature.geometry() + # Very rarely, there can be self-intersection. Try to fix it. + if not geometry.IsValid(): + geometry = geometry.MakeValid() + self.batch_boundary = self.batch_boundary.Union(geometry) self.batch_boundary_size += 1 if self.batch_boundary_size >= self.batch_size: self.boundary = self.boundary.Union(self.batch_boundary)