ds.rst.clip() or Raster.clip()

ds.rst.clip() or Raster.clip()#

RasterBase.clip(mask, all_touched=False, mp_config=None)[source]#

Mask raster cells outside an exact clipping geometry.

The raster grid and extent stay unchanged. Cells inside the geometry keep their values, while cells outside become masked values for Raster objects and NaN values for Xarray objects.

GCP/RPC referencing requires reproject() to an affine grid first.

Parameters:
  • mask (Any) – Clipping geometry, vector, point cloud, raster or bounding box. Georeferenced masks are reprojected to this raster’s CRS.

  • all_touched (bool) – Whether to keep every cell touched by the geometry. By default, keep cells whose center is inside the geometry, following Rasterio rasterization behavior.

  • mp_config (MultiprocConfig | None) – Multiprocessing configuration.

Return type:

RasterType

Returns:

Raster with cells outside the clipping geometry as NaN or masked.