| mask | R Documentation |
Keeps the pixels of a .vec raster whose cell centre falls inside a resident
polygon layer and sets the rest to background, reading the raster one
tile-row strip at a time so the whole grid is never resident. It is the raster
counterpart of spatial_clip(): the streamed side is the (large) raster and
the small mask layer stays in memory. With inverse = TRUE the inside is
cleared and the outside kept.
mask(
x,
mask,
inverse = FALSE,
band = NULL,
background = NA_real_,
path = NULL,
dtype = "f32",
compression = c("fast", "balanced", "max")
)
x |
A |
mask |
An |
inverse |
If |
band |
Band(s) to mask (1-based). Default |
background |
Value written to cleared pixels. Default |
path |
Optional output |
dtype |
Storage dtype for |
compression |
Compression effort for |
This is the monoid fold tier of the spatial toolbox: bounded to one strip plus the resident mask, a single streaming pass, no spill. A pixel is tested against the mask only when its centre falls in the mask bounding box, so the point-in-polygon work stays proportional to the overlap rather than the whole grid. Point-in-polygon is delegated to sf (an optional dependency); topology and CRS handling are sf's.
When path is NULL, a numeric matrix (one band) or a list of
matrices (several), each carrying gt, extent, and crs attributes
(row 1 northmost). When path is given, the written vectra_raster handle
(invisibly).
spatial_clip() for the vector analogue, zonal() for per-zone
summaries over the same pixel-in-polygon assignment.
vals <- matrix(1:100, 10, 10, byrow = TRUE)
f <- tempfile(fileext = ".vec")
vec_write_raster(vals, f, dtype = "f64", extent = c(0, 0, 10, 10))
disc <- sf::st_buffer(sf::st_sfc(sf::st_point(c(5, 5))), 3)
inside <- mask(f, disc)
sum(!is.na(inside))
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.