Skip to content

Commit

Permalink
Work around case of invalid boundary.
Browse files Browse the repository at this point in the history
Extremely rarely, data with holes can result in invalid
geometry.  Force it to be valid.
  • Loading branch information
akirmse committed Oct 4, 2024
1 parent a2e38d3 commit 64cbe43
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64cbe43

Please sign in to comment.