Mask values in a Raster object
mask.RdCreate a new Raster* object that has the same values as x, except for the cells that are NA (or other maskvalue) in a 'mask'. These cells become NA (or other updatevalue). 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 updatevalue. You can use inverse=TRUE to set the cells that are not NA (or other maskvalue) in the mask, or not covered by the Spatial* object, to NA (or other updatvalue).
Usage
# S4 method for class 'RasterLayer,RasterLayer'
mask(x, mask, filename="", inverse=FALSE,
maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...)
# S4 method for class 'RasterStackBrick,RasterLayer'
mask(x, mask, filename="", inverse=FALSE,
maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...)
# S4 method for class 'RasterLayer,RasterStackBrick'
mask(x, mask, filename="", inverse=FALSE,
maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...)
# S4 method for class 'RasterStackBrick,RasterStackBrick'
mask(x, mask, filename="", inverse=FALSE,
maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...)
# S4 method for class 'Raster,Spatial'
mask(x, mask, filename="", inverse=FALSE,
updatevalue=NA, updateNA=FALSE, ...)Arguments
- x
Raster* object
- mask
Raster* object or a Spatial* object
- filename
character. Optional output filename
- inverse
logical. If
TRUE, areas on mask that are _not_ themaskvalueare masked- maskvalue
numeric. The value in
maskthat indicates the cells ofxthat should becomeupdatevalue(default =NA)- updatevalue
numeric. The value that cells of
xshould become if they are not covered bymask(and notNA)- updateNA
logical. If
TRUE,NAvalues outside the masked area are also updated to the theupdatevalue(only relevant if theupdatevalueis notNA- ...
additional arguments as in
writeRaster