spatial_crop function

Crop extent of spatial data.

Crop extent of spatial data.

The function crops the spatial extent of raster objects or other spatial objects based on bounding box coordinates.

spatial_crop(data, bbox)

Arguments

  • data: raster object, spatial data set to be processed.
  • bbox: Numeric vector of length four, bounding box coordinates in the form c(xmin, xmax, ymin, ymax)

Returns

spatial object, cropped to bounding box

Examples

## create example data set x <- terra::rast(nrows = 100, ncols = 100, xmin = 0, xmax = 10, ymin = 0, ymax = 10) terra::values(x) <- 1:10000 ## create crop extent vector bbox <- c(3, 7, 3, 7) ## crop spatial object y <- spatial_crop(data = x, bbox = bbox) ## plot both objects terra::plot(x) terra::plot(y, add = TRUE)

Author(s)

Michael Dietze

  • Maintainer: Michael Dietze
  • License: GPL-3
  • Last published: 2025-03-25

Useful links