Skip to content

Commit

Permalink
FIX: Add more tolerances in geometry.simplify_footprint to allow fu…
Browse files Browse the repository at this point in the history
…rther simplification, and a warning in case of failure
  • Loading branch information
remi-braun committed Feb 13, 2025
1 parent 84316ce commit afce059
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.xx.x

- FIX: Add more tolerances in `geometry.simplify_footprint` to allow further simplification, and a warning in case of failure
- FIX: Force 2D geometries in `rasters.crop` as `odc.geo.xr.crop` don't work with 3D geometries
- OPTIM: Only write rasters on disk with `windowed=True` in case of big rasters _(w/*h > 20,000*20,000 pixels)_
- CI: Refactor `.gitlab-ci.yml` file with new GitLab templates
Expand Down
11 changes: 10 additions & 1 deletion sertit/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def simplify_footprint(
29
"""
# Number of pixels of tolerance
tolerance = [1, 2, 4, 8, 16, 32, 64]
tolerance = [1, 2, 4, 8, 16, 32, 64, 128, 256]

# Process only if given footprint is too complex (too many vertices)
def simplify_geom(value):
Expand All @@ -225,6 +225,15 @@ def simplify_geom(value):
nof_vertices = len(value.exterior.coords)
if nof_vertices <= max_nof_vertices:
break

# WARNING if nof_vertices > max_nof_vertices
nof_vertices = len(footprint.union_all().exterior.coords)
if nof_vertices > max_nof_vertices:
LOGGER.warning(
f"The number of vertices ({nof_vertices}) of your simplified footprint is higher than {max_nof_vertices}."
f"However, it cannot be simplified further according to the given resolution ({resolution})."
)

return value

footprint = footprint.explode(index_parts=True)
Expand Down

0 comments on commit afce059

Please sign in to comment.