
Lazily resample/reproject onto a target grid.
align_to.RdInserts an explicit warp step, executed as a GDAL VRT warp. Alignment stays explicit: binary ops never auto-resample.
Arguments
- x
A
LazyRaster.- to
Target grid: a
GridSpecor anotherLazyRaster.- resampling
GDAL resampling method. The default,
"near", copies source values unchanged, which categorical data (land cover, classes) and QA bitmasks need: interpolating them invents classes and bit patterns that do not exist. It matches the default oflazy_source()andlazy_dataset(). For continuous data (reflectance, elevation, temperature) choose"bilinear"(or"cubic") when resampling to a similar or finer resolution, and"average"when aggregating to a coarser one.
Details
Paste fast path: when x is already exactly on the target grid
(same CRS, transform, extent and dims; grid_equal()), align_to()
is a no-op returning x: reads stay plain windowed reads, with no
warp barrier splitting the plan. This is the single-CRS-zone
workflow: pin the analysis grid to the sources' native grid and
nothing warps. Only EXACT equality pastes (unlike odc-stac's
tolerance-based ttol): a sub-pixel-shifted paste would silently
move every pixel by up to half a cell, so near-misses warp.
Examples
f <- system.file("extdata", "garry-example.tif", package = "garry")
red <- lazy_source(f, band = 1L)
coarse <- grid_spec(crs = grid_crs(red), extent = grid_bbox(red), dims = c(30L, 20L))
dim(collect(align_to(red, coarse, resampling = "average")))
#> [1] 20 30