terra (version 0.2-10)

mask: Mask values in a SpatRaster

Description

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 the objects of a SpatVector. These cells become NA (or another updatevalue).

Usage

# S4 method for SpatRaster,SpatRaster
mask(x, mask, inverse=FALSE, maskvalue=NA, updatevalue=NA, filename="", overwrite=FALSE, wopt=list(), ...)
# S4 method for SpatRaster,SpatVector
mask(x, mask, inverse=FALSE, updatevalue=NA, filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

SpatRaster

mask

SpatRaster

inverse

logical. If TRUE, areas on mask that are _not_ the maskvalue are masked

maskvalue

numeric. The value in mask that indicates the cells of x that should become updatevalue (default = NA)

updatevalue

numeric. The value that cells of x should become if they are not covered by mask (and not NA)

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster object

See Also

crop

Examples

Run this code
# NOT RUN {
r <- rast(ncol=10, nrow=10)
m <- rast(ncol=10, nrow=10)
values(r) <- 1:100
x <- runif(ncell(r))
x[x < 0.5] <- NA
values(m) <- x
mr <- mask(r, m)
# }

Run the code above in your browser using DataLab