
x
, except for the cells that are NA
in a 'mask'. These cells become NA
. The mask can be either another Raster* object of the same extent and resolution, or a Spatial* object (e.g. SpatialPolygons) in which case all cells that are not covered by the Spatial object are set to NA
. You can use inverse=TRUE
to set the cells that are not NA
in the mask, or not coverd by the Spatial* object to NA
. When the mask is a Raster* object, you can also use another value than NA
in the mask object## S3 method for class 'RasterLayer,RasterLayer':
mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, ...)
## S3 method for class 'RasterStackBrick,RasterLayer':
mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, ...)
## S3 method for class 'RasterLayer,RasterStackBrick':
mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, ...)
## S3 method for class 'RasterStackBrick,RasterStackBrick':
mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, ...)
## S3 method for class 'Raster,Spatial':
mask(x, mask, filename="", inverse=FALSE, ...)
TRUE
, areas on mask that are _not_ NA
are masked. This option is only relevant if ]code{maskvalue=NA}mask
that indicates the cells of x
that should become NA
writeRaster
rasterize, crop
r <- raster(ncol=10, nrow=10)
m <- raster(ncol=10, nrow=10)
r[] <- runif(ncell(r)) * 10
m[] <- runif(ncell(r))
m[m < 0.5] <- NA
mr <- mask(r, m)
m2 <- m > .7
mr2 <- mask(r, m2, maskvalue=TRUE)
Run the code above in your browser using DataLab