⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂




Mask.crop(crop_geom, mode='match_pixel', *, inplace=False)[source]#

Crop the raster to a given extent.

Match-reference: a reference raster or vector can be passed to match bounds during cropping.

Reprojection is done on the fly if georeferenced objects have different projections.

  • crop_geom (Mask | Vector | list[float] | tuple[float, ...]) – Geometry to crop raster to. Can use either a raster or vector as match-reference, or a list of coordinates. If crop_geom is a raster or vector, will crop to the bounds. If crop_geom is a list of coordinates, the order is assumed to be [xmin, ymin, xmax, ymax].

  • mode (Union[Literal['match_pixel'], Literal['match_extent']]) – Whether to match within pixels or exact extent. 'match_pixel' will preserve the original pixel resolution, cropping to the extent that most closely aligns with the current coordinates. 'match_extent' will match the extent exactly, adjusting the pixel resolution to fit the extent.

  • inplace (bool) – Whether to update the raster in-place.

Return type:

Mask | None


A new raster (or None if inplace).