Combines several .vec rasters that share a resolution and cell grid into one
raster spanning their union, resolving overlap with fun. The output is
walked one tile-row strip at a time and each input contributes only the window
overlapping the current strip, so neither the inputs nor the output are held
whole in memory.
Arguments
- rasters
A list of
vectra_rasterhandles or.vecpaths sharing resolution and grid alignment.- fun
Overlap rule where inputs cover the same cell:
"first"(the earliest input inrasters, default),"last","mean","sum","min", or"max". Cells covered by no input come backNA.- band
Band read from every input (1-based). Default 1.
- path
Optional output
.vecpath. When given the result is streamed to disk and the openedvec_open_raster()handle is returned invisibly; whenNULLthe result is returned as an in-memory matrix.- dtype
Storage dtype for
.vecoutput (seevec_write_raster()). Default"f32".- compression
Compression effort for
.vecoutput. Default"fast".
Value
When path is NULL, a numeric matrix on the union grid (row 1
northmost) carrying gt, extent, and crs attributes. When path is
given, the written vectra_raster handle (invisibly).
Details
This is the monoid fold tier of the spatial toolbox: each output strip folds
the overlapping input windows, bounded memory, no spill. The inputs must share
resolution and lie on a common cell grid; warp() them onto a shared grid
first if they do not. No sf is needed.
See also
warp() to bring rasters onto a shared grid, rast_calc() for
cellwise combination of already-aligned rasters.
Examples
a <- matrix(1, 4, 4); b <- matrix(2, 4, 4)
fa <- tempfile(fileext = ".vec"); fb <- tempfile(fileext = ".vec")
vec_write_raster(a, fa, dtype = "f64", extent = c(0, 0, 4, 4))
vec_write_raster(b, fb, dtype = "f64", extent = c(2, 2, 6, 6))
m <- mosaic(list(fa, fb), fun = "mean")
dim(m)
unlink(c(fa, fb))