Learn R Programming

chronosphere (version 0.4.1)

mask,RasterArray,RasterLayer-method: Methods to mask RasterArray objects, or to mask with them

Description

Additional functions to mask generic function involving the RasterArray class. The following methods are implemented:

Usage

# S4 method for RasterArray,RasterLayer
mask(
  x,
  mask,
  inverse = FALSE,
  maskvalue = NA,
  updatevalue = NA,
  updateNA = FALSE,
  ...
)

# S4 method for RasterArray,RasterArray mask( x, mask, inverse = FALSE, maskvalue = NA, updatevalue = NA, updateNA = FALSE, ... )

# S4 method for RasterArray,Spatial mask(x, mask, inverse = FALSE, updatevalue = NA, updateNA = FALSE, ...)

# S4 method for RasterArray,RasterStackBrick mask( x, mask, inverse = FALSE, maskvalue = NA, updatevalue = NA, updateNA = FALSE, ... )

# S4 method for RasterLayer,RasterArray mask( x, mask, filename = "", inverse = FALSE, maskvalue = NA, updatevalue = NA, updateNA = FALSE, ... )

# S4 method for RasterStackBrick,RasterArray mask( x, mask, filename = "", inverse = FALSE, maskvalue = NA, updatevalue = NA, updateNA = FALSE, ... )

Value

A RasterArray or RasterLayer class object (see detaisl above).

Arguments

x

Raster* object

mask

Raster* object or a Spatial* object

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)

updateNA

logical. If TRUE, NA values outside the masked area are also updated to the updatevalue (only relevant if the updatevalue is not NA.

...

additional arguments as in writeRaster.

filename

character. Optional output filename (only if x is a RasterLayer and RasterStackBrick)

Details

RasterArray masked with RasterLayer: every RasterLayer in the stack masked.

RasterArray masked with another RasterArray: one-to-one match between RasterLayers.

RasterArray masked with RasterStack: one-to-one match between RasterLayers.

RasterArray masked with Spatial: all layers masked with an Sp object

RasterArray masked with Spatial: all layers masked with an Sp object

RasterLayer masked with RasterArray: layer is masked out iteratively with every member of RasterArray.

Examples

Run this code
data(dems)

# land
lands <- dems
for(i in 1:length(lands)){
  values(lands[i])[values(lands[i])<0] <- NA
  values(lands[i])[!is.na(values(lands[i]))] <- 1
}

# land topographies
landTopo<- mask(dems, lands)

Run the code above in your browser using DataLab