resize_spatial() mirrors the ergonomics of rayshader::resize_matrix(),
but returns a terra::SpatRaster with extent and CRS intact.
resize_spatial(
x,
scale = 1,
width = NULL,
height = NULL,
method_down = "mean",
method_up = "bilinear",
aggregate_if_possible = TRUE,
tol = 1e-08,
threads = FALSE,
filename = "",
overwrite = FALSE,
write_args = list(),
...
)Default 1. Relative output size used only when both width
and height are NULL.
Default NULL. Target number of columns. When supplied alone,
height is derived while preserving the current aspect ratio.
Default NULL. Target number of rows. When supplied alone,
width is derived while preserving the current aspect ratio.
Default "mean". Method used when reducing resolution.
Integer-factor reductions use terra::aggregate() when possible; other
reductions use terra::resample(). The default becomes "modal" when any
input layer is categorical.
Default "bilinear". Method passed to terra::resample()
when increasing resolution. The default becomes "near" when any input
layer is categorical.
Default TRUE. If TRUE, use
terra::aggregate() for integer-factor downsampling when method_down is an
aggregation method.
Default 1e-8. Tolerance for deciding whether an implied
aggregation factor is effectively an integer.
Default FALSE. Passed to terra::resample().
Default "". Optional output filename.
Default FALSE. Whether to overwrite filename.
Default list(). Named arguments passed only to
terra::writeRaster() when filename is supplied.
Arguments passed only to the resize operation that is used:
terra::aggregate() for aggregation or terra::resample() for resampling.
Downsampling and upsampling are handled separately because the best visual
method is often different in each direction. Integer-factor reductions can
use terra::aggregate(); everything else uses terra::resample() onto a
template raster with the requested geometry.