Skip to contents

Clips a raster to a polygon bounding box, optionally masks to polygon, and saves the output in the same format as the input.

Usage

clip_and_save_raster_file(
  input_path,
  polygon,
  out_path,
  mask = TRUE,
  overwrite = TRUE
)

Arguments

input_path

Character. Path to the input raster file.

polygon

An object or file coercible to a `SpatVector` by `terra::vect()` (e.g., an `sf` object, a `SpatVector`, or a file path to a vector dataset). used for clipping and masking. Must have a valid CRS.

out_path

Character. Path to save the processed raster.

mask

Logical: Should pixels outside the polygon but inside its bounding box be masked out (TRUE) or included (FALSE)?

overwrite

Logical: Replace output file if it already exists?

Value

Invisibly, the clipped `SpatRaster` object. The raster is also saved to `out_path`.

Author

David LeBauer