Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

Usage

## S4 method for signature 'SpatRaster,SpatRaster'
mask(x, mask, inverse=FALSE, maskvalues=NA, 
   updatevalue=NA, filename="", ...)
   
## S4 method for signature 'SpatRaster,SpatVector'
mask(x, mask, inverse=FALSE, updatevalue=NA,
	touches=TRUE, filename="", ...)

Arguments

x

SpatRaster

mask

SpatRaster

inverse

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

maskvalues

numeric. The value(s) 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)

touches

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

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

See Also

Examples

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)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.