fragmentation,SpatRaster-method | R Documentation |
Riitters et al. (2020) propose a classification scheme for forest fragmentation (which can be applied to any habitat type). The scheme relies on calculating density (e.g., number of forested cells in a window around a focal cell) and connectivity (number of cases where neighboring cells are both forested). This function calculates these classes from a GRaster
or SpatRaster
in which the focal habitat type has cell values of 1, and non-focal habitat type has cell values of 0 or NA
.
Note that by default, the SpatRaster
and GRaster
versions will create different results around the border of the raster. The SpatRaster
version uses the terra::focal()
function, which will not return an NA
value when its window overlaps the raster border if the na.rm
argument is TRUE
. However, the GRaster
version uses the GRASS module r.neighbors
, which does return NA
values in these cases.
The fragmentation classes are:
Value provided by none
: None (i.e., no forest; default is NA
).
1: Patch
2: Transitional
3: Perforated
4: Edge
5: Undetermined (not possible to obtain when w = 3
)
6: Interior
## S4 method for signature 'SpatRaster'
fragmentation(
x,
w = 3,
undet = "undetermined",
none = NA,
na.rm = TRUE,
cores = faster("cores"),
verbose = TRUE
)
## S4 method for signature 'GRaster'
fragmentation(x, w = 3, undet = "undetermined", none = NA, verbose = TRUE)
x |
A |
w |
An odd, positive integer: Size of the window across which fragmentation is calculated (in units of "rows" and "columns"). The default is 3, meaning the function uses a 3x3 moving window to calculate fragmentation. For large rasters, compute time is ~O( |
undet |
Character: How to assign the "undetermined" case. Valid values are |
none |
Integer or |
na.rm |
Logical: If |
cores |
Integer: Number of processor cores to use for when processing a |
verbose |
Logical: If |
A categorical SpatRaster
or GRaster
. The values assigned to each class can be seen with levels()
.
Riitters, K., J. Wickham, R. O'Neill, B. Jones, and E. Smith. 2000. Global-scale patterns of forest fragmentation. Conservation Ecology 4:3. URL: http://www.consecol.org/vol4/iss2/art3/. Also note the errata.
if (grassStarted()) {
# Setup
library(terra)
# Example data:
madForest <- fastData("madForest2000") # raster
### Fragmentation classes from a SpatRaster
fragTerra <- fragmentation(madForest)
plot(fragTerra)
levels(fragTerra)
freq(fragTerra)
### Fragmentation classes from a GRaster
# Convert to GRaster:
forest <- fast(madForest)
# Fragmentation class:
frag <- fragmentation(forest)
plot(frag)
levels(frag)
freq(frag)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.