mask: Mask values in a Raster object

Description Usage Arguments Details Value Examples

Description

Create 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, a sf object, or a Spatial* object (e.g. SpatialPolygons) in which case all cells that are not covered by the sf/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

1
mask(x, mask, ...)

Arguments

x

Raster* object

mask

Raster* object, sf object, or a Spatial* object

...

additional arguments as in writeRaster

Details

See mask for more details.

Value

Raster* object

Examples

1
2
3
4
5
6
x <- read_sf(system.file("shape/nc.shp", package="sf"))
new_raster <- raster(x)
new_raster[] <- sample(seq_len(ncell(new_raster)))
raster_masked <- mask(new_raster, x)
plot(raster_masked)
plot(x, add = TRUE)

mdsumner/sfraster documentation built on May 12, 2019, 1:05 p.m.