| focal | R Documentation |
Applies a moving window to a .vec raster, reading the input one tile-row
strip at a time – each strip expanded by the kernel radius (a halo read) so
window neighbours are available without ever holding the whole grid resident.
The per-window statistic is computed in C. When path is given the output is
streamed straight back to a new .vec one tile-row at a time, so neither the
input nor the output band is ever fully in memory; this is the raster op that
runs out of core where an in-memory engine needs the whole raster at once.
focal(
x,
w = matrix(1, 3, 3),
fun = c("mean", "sum", "min", "max", "sd", "median"),
na.rm = TRUE,
band = 1L,
path = NULL,
dtype = "f32",
compression = c("fast", "balanced", "max")
)
x |
A |
w |
A numeric weight matrix with odd dimensions, or a single positive
odd integer |
fun |
Window statistic: one of |
na.rm |
Skip nodata cells inside the window ( |
band |
Band to read (1-based). Default 1. |
path |
Optional output |
dtype |
Storage dtype for |
compression |
Compression effort for |
This is the sort / partition tier of the spatial toolbox: bounded to one haloed strip at a time, exploiting tile locality.
The window w is a numeric weight matrix with odd dimensions (or a single
odd integer k, shorthand for a k x k matrix of ones). NA weights mark
cells outside the window. For fun = "sum"/"mean" the weights scale the
values (sum is sum(w * x), mean is sum(w * x) / sum(w)); for the other
statistics a finite weight only marks membership. With na.rm = TRUE (the
default) nodata cells inside the window are skipped; with na.rm = FALSE any
nodata cell – including a window that runs off the raster edge – makes the
result NA, matching the resident behaviour.
When path is NULL, a numeric matrix (row 1 northmost) carrying
gt, extent, crs, and fun attributes. When path is given, the
written vectra_raster handle (invisibly).
terrain() for DEM derivatives built on the same strip pass,
zonal() for per-zone summaries.
m <- matrix(1:36, 6, 6, byrow = TRUE)
f <- tempfile(fileext = ".vec")
vec_write_raster(m, f, dtype = "f64", extent = c(0, 0, 6, 6))
# 3x3 mean smoother; edge cells see off-raster neighbours.
focal(f, w = matrix(1, 3, 3), fun = "mean")
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.