regionMask | R Documentation |
Function that converts raster and SpatialPolygon* objects to a list of cells that fall within such a region.
regionMask(
region,
proj = crs(region),
id = NULL,
z_fix = NULL,
precision = 2,
...
)
region |
An object of class SpatRaster, Raster*, SpatVector, or SpatialPolygon* to convert to "x,y" |
proj |
A crs object or character string representing the output
projection. Default is |
id |
A character string indicating which column in a Spatial* or Spat* contains each feature's unique ID. Otherwise ignored |
z_fix |
A SpatRaster with the same origin and resolution as the
|
precision |
An integer representing the number of decimals to retain
in the x and y directions. For grid sizes with nice, round numbers precisions
can be low. This factor is controled by |
... |
Additional arguments to pass to |
A character vector containing all cells that fall in the same
location as the input 'region'. If id
is provided, a data.table.
# Generate a DEM
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) +
250 * exp(-(y - n/2)^2)]
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
# Generate a polygon that falls within the DEM's extent
region <- ext(c(12500,12600,32500,32700))
region <- as.polygons(region)
crs(region) <- crs(dem)
maskedCells <- regionMask(region = region, res = res(dem))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.