expandClass: Expand an existing class of patches.

View source: R/expandClass.R

expandClassR Documentation

Expand an existing class of patches.

Description

Expand an existing class of patches.

Usage

expandClass(context, class, size, bgr = 0, pts = NULL)

Arguments

context

SpatRaster object or matrix, an empty landscape raster or a mask indicating where the patch cannot be generated (see bgr below).

class

The raster value of class (or patch) to expand.

size

integer. Size of expansion, as number of raster cells.

bgr

integer. The background available where expansion is allowed (i.e. shrinking classes).

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.

Value

A SpatRaster object. If rast=FALSE returns a list of vectors, each containing the context cells assigned to each patch.

Examples

library(terra)

m = matrix(0, 33, 33)
r = rast(m)
ext(r) = c(0, 10, 0, 10)
r = makeClass(r, 5, 10)
plot(r)

rr = expandClass(r, 1, 100)
plot(rr)

## This function can be used to mimic shapes, by providing a skeleton:
m[,17] = 1
r = rast(m)
ext(r) = c(0, 10, 0, 10)
plot(r)

rr = expandClass(r, 1, 100)
plot(rr)

landscapeR documentation built on Nov. 2, 2024, 1:07 a.m.