get_patches | R Documentation |
Connected components labeling to derive patches in a landscape.
get_patches(
landscape,
class = "all",
directions = 8,
to_disk = getOption("to_disk", default = FALSE),
return_raster = TRUE
)
landscape |
A categorical raster object: SpatRaster; Raster* Layer, Stack, Brick; stars or a list of SpatRasters. |
class |
Either "all" (default) for every class in the raster, or specify class value. See Details. |
directions |
The number of directions in which patches should be connected: 4 (rook's case) or 8 (queen's case). |
to_disk |
Logical argument, if FALSE results of get_patches are hold
in memory. If true, get_patches writes temporary files and hence, does not hold everything in memory.
Can be set with a global option, e.g. |
return_raster |
If false, matrix is returned |
Searches for connected patches (neighbouring cells of the same class i).
The 8-neighbours rule ('queen's case) or 4-neighbours rule (rook's case) is
used. Returns a list with raster. For each class the connected patches have
the value 1 - n. All cells not belonging to the class are NA
.
Landscape metrics rely on the delineation of patches. Hence, get_patches
is
heavily used in landscapemetrics. As raster can be quite big, the fact that
get_patches
creates a copy of the raster for each class in a landscape becomes
a burden for computer memory. Hence, the argument to_disk allows to
store the results of the connected labeling algorithm on disk. Furthermore,
this option can be set globally, so that every function that internally uses
get_patches
can make use of that.
List of SpatRaster
Vincent, L., Soille, P. 1991. Watersheds in digital spaces: an efficient algorithm based on immersion simulations. IEEE Transactions on Pattern Analysis and Machine Intelligence. 13 (6), 583-598
landscape <- terra::rast(landscapemetrics::landscape)
# check for patches of class 1
patched_raster <- get_patches(landscape, class = 1)
# count patches
nrow(terra::unique(patched_raster[[1]][[1]]))
# check for patches of every class
patched_raster <- get_patches(landscape)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.