
Project a SpatRaster onto a grid aligned to multiples of a target resolution
Source:R/project_aligned.R
project_aligned.Rdproject_aligned() projects x into the target crs at resolution
res_m, with cells aligned to multiples of res_m (i.e. origin at 0,
0). It is a workaround for terra >= 1.9-25, which errors with
[write] unknown option(s): xscale,yscale whenever res or origin
is passed alongside a CRS-string target in terra::project(). The
template-raster path used here is unaffected.
Arguments
- x
A SpatRaster.
- crs
Target coordinate reference system as accepted by
terra::crs().- res_m
Target cell size in the units of
crs(typically meters).- method
Resampling method passed to
terra::project().
Details
Internally it projects the source extent (cheap), snaps outward to
multiples of res_m with one cell of buffer on each side (to absorb
the difference between corner-only extent projection and the true
bounding box of a non-rectangular reprojected raster), constructs an
empty template SpatRaster with that grid, then projects x against
the template.