Skip to content

FIX: Clip the AOI by the scene footprint before SNAP's Subset - #333

Merged
remi-braun merged 2 commits into
mainfrom
fix/snap-subset-aoi
Oct 8, 2026
Merged

remi-braun merged 2 commits into
mainfrom
fix/snap-subset-aoi

Conversation

@A220N1

@A220N1 A220N1 commented Oct 5, 2026

Copy link
Copy Markdown

Closes #331

Problem

When the AOI goes beyond the image footprint, the polygon given to SNAP's Subset (vectorFile) has vertices outside the image. SNAP 13 moves them to pixel (0, 0). The orthorectified bands come out cut or empty.

665487761-1f56be6d-6a4a-4893-abbb-e88931f78a1d

Changes

  • _get_subset: AOI is clipped by the scene footprint shrunk by 100 m, as a single polygon without holes. A ValueError is raised if it does not intersect the product. The vector file becomes *_snap_subset.shp, so unclipped files from older versions are not reused.
  • _wgs84_footprint(): scene footprint read from the metadata (KML, or GCPs without KML). wgs84_extent() is unchanged when the KML exists.
  • _fallback_wgs84_extent: for images without KML, polygon of the GCPs on the image border, instead of an affine fit applied to the image corners, which is up to 2 km off on large scenes.
  • Unit tests and CHANGES.
iceye_singapore

Behaviour change

Without an extent file, wgs84_extent() now comes from the GCP footprint instead of the affine fit.

@remi-braun remi-braun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good !

Comment thread eoreader/products/sar/sar_product.py Outdated
from sertit.vectors import WGS84
from shapely.geometry.polygon import Polygon
from shapely.geometry import MultiPoint, Point, Polygon
from shapely.ops import unary_union

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unary_union exists in geopandas now, don't use shapely's

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested geopandas' unary_union. It's Ok, though it raise a DeprecationWarning with geopandas > 1.0 because it has been replaced by union_all() since 1.0 or even before maybe ?
So we can leave it like that with unary union, or change geopandas>=1.0 instead of >=0.14.4

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In geopandas 1.1.4 :
test_point1_patched.py::test_snap_subset_polygon (×4) eoreader/products/sar/sar_product.py:87: DeprecationWarning: The 'unary_union' attribute is deprecated, use the 'union_all()' method instead. polygon = aoi.unary_union.intersection(footprint)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use union_all 😉

Comment thread eoreader/products/sar/sar_product.py Outdated
Returns:
gpd.GeoDataFrame: Single polygon without hole, in the AOI CRS
"""
footprint = unary_union(footprint.to_crs(aoi.crs).buffer(-margin))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • did you check that aoi is projected?
  • use geopandas's unary union

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the aoi is projected ans so always in a UTM zone in metres

@A220N1

A220N1 commented Oct 8, 2026

Copy link
Copy Markdown
Author

Done ✅
union_all(), with geopandas>=1.0.0

@remi-braun
remi-braun merged commit 2c4a596 into main Oct 8, 2026
6 checks passed
@remi-braun
remi-braun deleted the fix/snap-subset-aoi branch October 8, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAR: cut or empty bands when the AOI extends beyond the product

2 participants