preprocessing.clip_to_geometry
preprocessing.clip_to_geometry(
tiff_path,
geometries,
*,
geometry_crs='EPSG:4326',
all_touched=False,
)Set pixels outside the polygon(s) to NaN in a GeoTIFF, in place.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| tiff_path | str | A floating-point GeoTIFF, such as the <Mission>_full_size.tiff written by :func:geoai_datacubes.fetch.fetch_sentinel_data. |
required |
| geometries | dict, object with __geo_interface__, or list of them |
Polygon / MultiPolygon geometries, Features or a FeatureCollection, for example the output of :func:geoai_datacubes.fetch.resolve_aoi_geometry. Interior rings (holes) are honoured; pixels inside a hole are set to NaN. |
required |
| geometry_crs | str | CRS of geometries. Defaults to WGS84, which is what resolve_aoi_geometry returns. |
'EPSG:4326' |
| all_touched | bool | If True, keep every pixel the polygon touches; if False (default), keep only pixels whose centre falls inside it. | False |
Returns
| Name | Type | Description |
|---|---|---|
| int | Number of pixels (per band) that were set to NaN. |
Notes
Tiles that straddle the polygon edge pick up NaN pixels, so with tile_geotiff(nan_handling="auto" | "drop" | "interpolate") they may exceed nan_max_fraction and be dropped. Use nan_handling="mask" to keep them with a validity band instead.