Skip to content

Add polygon clipping function (#1144)#1173

Open
brendancol wants to merge 1 commit intomasterfrom
issue-1144
Open

Add polygon clipping function (#1144)#1173
brendancol wants to merge 1 commit intomasterfrom
issue-1144

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • clip_polygon() masks raster pixels outside a polygon to nodata (NaN by default), with optional bounding-box crop
  • All four backends: numpy, dask+numpy, cupy, dask+cupy
  • Accepts shapely Polygon/MultiPolygon, geometry lists, GeoDataFrame/GeoSeries, or raw [(x, y), ...] coords
  • Uses rasterize() internally for the polygon-to-mask step

What changed

  • xrspatial/polygon_clip.py — new module with clip_polygon()
  • 20 tests across all backends, edge cases (NaN input, single-cell raster, non-overlapping geometry), GeoDataFrame/GeoSeries
  • .xrs.clip_polygon() accessor on DataArrays
  • API entry in docs/source/reference/zonal.rst
  • User guide notebook: examples/user_guide/50_Polygon_Clipping.ipynb
  • README feature matrix row under Zonal

Test plan

  • pytest xrspatial/tests/test_polygon_clip.py — 20/20 passing
  • Verify notebook renders correctly
  • Verify docs build with make html

`clip_polygon()` masks pixels outside a polygon to nodata, with optional
bbox crop. Supports all four backends. Accepts shapely geometries,
GeoDataFrames, or coordinate lists.

Adds 20 tests, API docs, user guide notebook, and README entry.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant