makeClass | R Documentation |
Create a class of patches.
makeClass(
context,
npatch,
size,
pts = NULL,
bgr = 0,
edge = FALSE,
rast = TRUE,
val = 1
)
context |
SpatRaster object, a raster of an empty landscape or a mask, indicating where the patch cannot be generated (see |
npatch |
number of patches per class |
size |
integer. The size of patches, as number of raster cells. A single integer can be provided, in which case all patches will have that size. |
pts |
integer or matrix. The seed point location around which the patches are built (random points are given by default). It can be an integer, as indexes of the cells in the raster, or a two columns matrix indicating x and y coordinates. |
bgr |
integer. A single value of background cells, where a patch can be generated (default is zero). Cells/classes which cannot be changed must have a different value. |
edge |
logical. Should the vector of edge cells of the patch be returned? |
rast |
logical. If TRUE returns a SpatRaster object, otherwise a vector of cell numbers where the patch occurs |
val |
integer. The value to be assigned to patch cells, when |
The patches created can be contiguous, therefore resembling a single patch with size
equal to the sum of contiguous cells. The patches are created starting from the seed points (if provided) and iteratively sampling randomly neighbouring cells at the edge of the patch, according to von Neumann neighbourhood (four cells, aka Rook case).
There is a tolerance of +/- 3 cells from the patch size declared in size
argument.
A SpatRaster object, or a vector of cell numbers if rast=FALSE
.
library(terra)
mtx = matrix(0, 33, 33)
r = rast(mtx)
ext(r) = c(0, 10, 0, 10)
num = 5
size = 15
rr = makeClass(r, num, size)
plot(rr)
## Create a class of three patches of given size at three corners of the spatial context
size = c(10, 50, 200)
pts = c(1, 33, 1089)
rr = makeClass(r, 3, size, pts)
plot(rr)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.