Quickly partition a large raster mosaic into individual tiles using a
polygon layer. Each tile is clipped by either the polygon's bounding box
or (optionally) the exact feature geometry, and written to disk as a separate
GeoTIFF named by the feature's unique_id
.
mosaic_clip(
mosaic,
shapefile,
unique_id = "unique_id",
out_dir = NULL,
overwrite = TRUE,
verbose = TRUE,
exact = FALSE,
parallel = FALSE,
workers = NULL
)
Invisibly returns a character vector of file paths to all clipped GeoTIFFs.
A terra::SpatRaster object or a file path pointing to a raster. In-memory rasters are first written to a temporary GeoTIFF.
An sf::sf, terra::SpatVector, or path to a vector file. Must
contain a column named unique_id
for naming each output tile.
A column present in shapefile
that uniquely identifies the
plots to be clipped.
Directory where clipped rasters will be saved. Defaults to the current working directory. Created recursively if it does not exist.
Logical; if TRUE
(the default), existing files in out_dir
with the
same name will be overwritten.
Logical; if TRUE
(default), progress bars and status messages will be
shown.
Logical; if FALSE
(default), tiles are cropped by each feature's
bounding box. If TRUE
, the function extracts each polygon as a cutline
for an exact crop (slower, but shape-accurate).
Logical; if TRUE
(default), processing is parallelized using mirai
.
Set to FALSE
for purely sequential execution.
Integer; number of parallel daemons to launch when parallel = TRUE
.
Defaults to 70% of available cores.
Clip a Raster Mosaic by Polygons
This function wraps GDAL's warp
utility for efficient raster clipping.
When parallel = TRUE
, it will spawn multiple workers via mirai
and
process tiles in batches. Use exact = TRUE
to clip to the true polygon
shape (at some extra cost), or leave exact = FALSE
for a faster
bounding-box crop.