patch_config | R Documentation |
Given a set of patches in raster or vector format, calculate the areas and interpatch distances.
patch_config(x, units = c("m", "km"))
x |
patch network in raster or vector format, see Details. |
units |
character; whether distances and areas should be in meters or kilometers. |
If the patch network is provided as a Raster
object, cells included in the
network should be 1, and background cells should be 0 or NA
. Patches can
also be provided as polygons from either the sf
or sp
packages. Spatial
data must be provided in projected coordinates with units of meters.
A patch_config
object with two elements: the interpatch distances
(distances
) and patch areas (areas
).
# raster
r <- raster::raster(nrows = 10, ncols = 10, crs = "+proj=laea")
r[] <- round(runif(raster::ncell(r)) * 0.7)
patch_config(r, units = "m")
# polygon
p_poly <- raster::rasterToPolygons(r, dissolve = TRUE)
p_poly <- sf::st_as_sf(p_poly)
p_poly <- p_poly[p_poly$layer == 1, ]
p_poly <- sf::st_cast(p_poly, "POLYGON")
patch_config(p_poly, units = "km")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.