geo-registry

Clip raster

Cuts a raster to a polygon mask or a bounding box.

Pitfall. Cells outside the mask become nodata; a raster without a nodata value turns them into real zeros.
About this operation
Also called Clip Raster, Extract by Mask, Clip raster by mask layer, Clip raster by extent
Group raster/extraction
Checks crs.agreement, raster.nodata
Pitfalls 1 listed above
Columbus tool raster_op · clip
Notes Not stated
Status active
Broader Not stated
Narrower Not stated
Related

Parameters

Name Type Required Default Values Note
bbox extent no Not stated Not stated Used when there is no mask.
bbox_crs crs no Not stated Not stated Not stated
all_touched boolean no Not stated Not stated Keep every cell the mask touches, not only cells whose centre is inside.

Inputs and outputs

Direction Name Type Geometry Note
Input raster raster Not stated Not stated
Input mask vector polygon Optional; a bbox can be given instead.
Output output raster Not stated Not stated

In each engine

Engine Tool Parameters Differences
gdal gdal raster clip
  • bbox → bbox
  • bbox_crs → bbox-crs
  • raster → input
  • mask → like
  • output → output
None noted
postgis-raster st_clip
  • bbox Pass the box as a geometry (ST_MakeEnvelope).
  • all_touched → touched
  • raster → rast
  • mask → geom
None noted
qgis gdal:cliprasterbymasklayer
  • raster → INPUT
  • mask → MASK
  • output → OUTPUT
  • Runs GDAL's warp underneath; CROP_TO_CUTLINE (on by default) shrinks the output to the mask's extent.
rasterio rasterio.mask.mask
  • bbox Pass the box as a polygon in shapes.
  • all_touched → all_touched
  • raster → dataset
  • mask → shapes
  • Takes an open dataset and GeoJSON-like shapes in the raster's CRS; returns an array and its transform rather than writing a file.
  • Without crop = True the result keeps the full extent, with cells outside the shapes set to nodata.
Preset: {"crop":true}
rioxarray rioxarray.raster_array.RasterArray.clip
  • bbox Use clip_box(minx, miny, maxx, maxy, crs=...) for a box.
  • all_touched → all_touched
  • mask → geometries
  • Called through the .rio accessor of a DataArray (da.rio.clip); crs gives the geometries' CRS when it differs from the raster's.
terra terra::crop
  • bbox Pass the box as a SpatExtent (ext(xmin, xmax, ymin, ymax)) in y.
  • all_touched → touches
  • raster → x
  • mask → y
  • touches defaults to TRUE (cells touched by the mask are kept); Columbus and GDAL default to cell centres.
  • Without mask = TRUE, crop only cuts to the mask's extent.
Preset: {"mask":true}
whiteboxtools ClipRasterToPolygon
  • raster → input
  • mask → polygons
  • output → output
None noted