Create a new SpatRaster that has the same values as SpatRaster x
, except for the cells that are NA
(or another maskvalue
) in another SpatRaster (the 'mask'), or not covered by a SpatVector. These cells become NA
(or another updatevalue
).
# S4 method for SpatRaster,SpatRaster
mask(x, mask, inverse=FALSE, maskvalues=NA,
updatevalue=NA, filename="", overwrite=FALSE, wopt=list(), ...)
# S4 method for SpatRaster,SpatVector
mask(x, mask, inverse=FALSE, updatevalue=NA,
touches=is.lines(mask), filename="", overwrite=FALSE, wopt=list(), ...)
SpatRaster
SpatRaster
logical. If TRUE
, areas on mask that are _not_ the maskvalue
are masked
numeric. The value(s) in mask
that indicates the cells of x
that should become updatevalue
(default = NA
)
numeric. The value that cells of x
should become if they are not covered by mask
(and not NA
)
logical. If TRUE
, all cells touched by lines or polygons will be masked, not just those on the line render path, or whose center point is within the polygon
character. Output filename. Optional
logical. If TRUE
, filename
is overwritten
list. Options for writing files as in writeRaster
additional arguments. None implemented
SpatRaster
# NOT RUN {
r <- rast(ncol=10, nrow=10)
m <- rast(ncol=10, nrow=10)
values(r) <- 1:100
set.seed(1965)
x <- round(3 * runif(ncell(r)))
x[x==0] <- NA
values(m) <- x
mr <- mask(r, m)
# }
Run the code above in your browser using DataLab