| resistanceFromShape | R Documentation |
Creates a resistance raster to be used in simulations, by rasterizing and combining different shapefiles.
It is basically a helper function that uses the functions from package terra-package to create and manipulate
such raster.
resistanceFromShape(shp, baseRaster, res, binary = is.na(field)
, field = NA, background = 1, buffer = NA, margin = 0
, mapvalues = NA, extend = TRUE, ...)
shp |
either a character string specifying the shapefile filename or a shapefile object itself. |
baseRaster |
if provided, a raster onto which to stack the given rasterized shapefile. If not provided, a new raster will be created. |
res |
the desired pixel resolution of the raster to be created, when |
binary |
if TRUE, the shapefile will be rasterized so that any feature is assigned a value of 0, and the background 1. |
field |
either a number in the range [0-1], in which case it will be assigned to all pixels covered by features of the shapefile; or the name of the numeric shapefile field from which to extract such number; or the name of the factor shapefile field containing classes to map to resistance values (see |
background |
the value in the range [0-1] to assign to all pixels that are not covered by any shapefile feature. |
buffer |
the size of a buffer to build around every shapefile feature before rasterizing. |
margin |
the margin to leave around the shapefile's extent when rasterizing (i.e. how much to increase shapefile's extent). |
mapvalues |
a named vector specifying the resistance value mapping from the classes of |
extend |
set to TRUE to extend |
... |
other arguments to pass to |
This function rasterizes the given shapefile using provided options and optionally stacks it onto the provided baseRaster.
The produced raster does not contain NAs and all values are in the range [0, 1]. All the areas of the raster for which data is not provided are assigned the value of background.
When combining a shapefile to an existing baseRaster, only the areas covered by features are updated in the base raster;
all the remaining areas are left with the original values of baseRaster. If the shapefile to combine has a larger extent than baseRaster,
those extra pixels will be assigned the background value defined for the shapefile (not use the original background of baseRaster).
The resistance raster, an object of class SpatRaster-class.
simulate.
## Example taken from the vignette; see the vignette
## for more details and examples.
## In this example we read a land cover shapefile and
## assign resistance values based on each polygon's
## land cover class (provided in the field 'coverclass')
landcover <- resistanceFromShape(
system.file("doc/landcover.shp", package="SiMRiv")
, res = 150, field = "coverclass", mapvalues = c(
"forest" = 0.5, "urban" = 1, "dam" = 0
, "shrubland" = 0.75), background = 0.95)
## We then combine it with a river network from another
## shapefile, assigning a value of 0 to all rivers
river.landcover <- resistanceFromShape(
system.file("doc/river-sample.shp", package="SiMRiv")
, baseRaster = landcover, buffer = 100, field = 0
, background = 0.95, margin = 1000)
plot(river.landcover, axes = FALSE, mar = c(0, 0, 0, 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.