Title: | Categorical Landscape Simulation Facility |
---|---|
Description: | Simulates categorical maps on actual geographical realms, starting from either empty landscapes or landscapes provided by the user (e.g. land use maps). Allows to tweak or create landscapes while retaining a high degree of control on its features, without the hassle of specifying each location attribute. In this it differs from other tools which generate null or neutral landscapes in a theoretical space. The basic algorithm currently implemented uses a simple agent style/cellular automata growth model, with no rules (apart from areas of exclusion) and von Neumann neighbourhood (four cells, aka Rook case). Outputs are raster dataset exportable to any common GIS format. |
Authors: | Dario Masante [aut, cre], Lora Murphy [ctb] |
Maintainer: | Dario Masante <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.3.1 |
Built: | 2024-12-07 20:32:29 UTC |
Source: | CRAN |
This package is aimed at simulating categorical landscapes on actual geographical realms, starting from either empty landscapes, or landscapes provided by the user (e.g. land use maps). landscapeR allows to tweak or create landscapes while retaining a high degree of control on its features, without the hassle of specifying each location attribute. In this it differs from other tools which generate null or neutral landscape in a theoretical space. The basic algorithm currently implemented uses a simple agent style/cellular automata growth model, with no rules (apart from areas of exclusion). Outputs are raster dataset exportable to any common GIS format.
Check out the vignette illustrating the use of landscapeR.
Also: https://github.com/dariomasante/landscapeR
makePatch
creates a single patch in the landscape.
makeClass
creates a group of patches belonging to the same class.
expandClass
expands an existing class of patches.
makeLine
creates a linear patch.
rmSingle
removes single tones from patches and background.
Dario Masante [aut, cre], Lora Murphy [ctb]
Expand an existing class of patches.
expandClass(context, class, size, bgr = 0, pts = NULL)
expandClass(context, class, size, bgr = 0, pts = NULL)
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. |
A SpatRaster object. If rast=FALSE
returns a list of vectors, each containing the context
cells assigned to each patch.
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)
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)
Create a class of patches.
makeClass( context, npatch, size, pts = NULL, bgr = 0, edge = FALSE, rast = TRUE, val = 1 )
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)
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)
Create a linear patch, setting direction and convolution. The higher the convolution degree, the weaker the linear shape (and direction).
makeLine( context, size, direction = NULL, convol = 0.5, spt = NULL, bgr = 0, edge = FALSE, rast = FALSE, val = 1 )
makeLine( context, size, direction = NULL, convol = 0.5, spt = NULL, bgr = 0, edge = FALSE, rast = FALSE, val = 1 )
context |
SpatRaster object or matrix, an empty landscape raster or a mask indicating where the patch cannot be generated (see bgr below). |
size |
integer. Size of the patch to be generated, as number of raster cells. |
direction |
numeric. The direction towards which the patch will point and grow, expressed in degrees between 0 and 360. |
convol |
numeric. Level of convolution to be assigned to the patch (default is |
spt |
integer or matrix. The seed point location around which the patch is generated (a random point is given by default). It can be an integer, as index of the cell in the raster, or a two columns matrix indicating x and y coordinates (an integer vector of length 2 is accepted too). |
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 |
For any values of convol
> 0.8, no big differences are observed noted. Also direction is progressively lost
as convolution increases.
A vector of raster cell numbers, or a SpatRaster object if rast=TRUE
. If edge=TRUE
a
list of two vectors is returned: one for the inner raster cells and the second for cells at the edge of the patch.
library(terra) r <- matrix(0,33,33) r <- rast(r) ext(r) = c(0, 10, 0, 10) plot(makeLine(r, size=50, spt = 545, direction=45, convol=0.05, rast=TRUE))
library(terra) r <- matrix(0,33,33) r <- rast(r) ext(r) = c(0, 10, 0, 10) plot(makeLine(r, size=50, spt = 545, direction=45, convol=0.05, rast=TRUE))
Function will create a single patch. NOTE: makeClass
should be used preferably when creating a single patch, as better error and exception handling is provided.
makePatch( context, size, spt = NULL, bgr = 0, edge = FALSE, rast = FALSE, val = 1 )
makePatch( context, size, spt = NULL, bgr = 0, edge = FALSE, rast = FALSE, val = 1 )
context |
SpatRaster object or matrix, an empty landscape raster or a mask indicating where the patch cannot be generated (see bgr below). |
size |
integer. Size of the patch to be generated, as number of raster cells. |
spt |
integer or matrix. The seed point location around which the patch is generated (a random point is given by default). It can be an integer, as index of the cell in the raster, or a two columns matrix indicating x and y coordinates (an integer vector of length 2 is accepted too). |
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 patch is created starting from the seed point 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.
Argument bgr
accepts a single value only, unlike makeClass
that accepts multiple and should therefore preferred.
A vector of raster cell numbers, or a SpatRaster object if rast=TRUE
. If edge=TRUE
a
list of two vectors is returned: one for the inner raster cells and the second for cells at the edge of the patch.
library(terra) mtx = matrix(0, 33, 33) r = rast(mtx) ext(r) = c(0, 10, 0, 10) patchSize = 500 rr = makePatch(r, patchSize, rast=TRUE) plot(rr) ## Create a patch with value 3, starting from the centre cell mtx = matrix(0, 33, 33) r = rast(mtx) ext(r) = c(0, 10, 0, 10) newVal = 3 centre = 545 cells = makePatch(r, patchSize, centre) values(r) = newVal plot(r) ## Now create a new patch with value 10 and size 100 inside the existing patch rr = makePatch(r, 100, bgr=newVal, rast=TRUE, val=10) plot(rr)
library(terra) mtx = matrix(0, 33, 33) r = rast(mtx) ext(r) = c(0, 10, 0, 10) patchSize = 500 rr = makePatch(r, patchSize, rast=TRUE) plot(rr) ## Create a patch with value 3, starting from the centre cell mtx = matrix(0, 33, 33) r = rast(mtx) ext(r) = c(0, 10, 0, 10) newVal = 3 centre = 545 cells = makePatch(r, patchSize, centre) values(r) = newVal plot(r) ## Now create a new patch with value 10 and size 100 inside the existing patch rr = makePatch(r, 100, bgr=newVal, rast=TRUE, val=10) plot(rr)
Patch creation algorithm can occasionally leave single cells scattered within patches. This function reduces the "salt-pepper" effect, identifying or correcting those cells.
rmSingle(rst, rm = TRUE)
rmSingle(rst, rm = TRUE)
rst |
input raster landscape. |
rm |
logical, if TRUE returns the raster without single tones cells, if FALSE a vector of numbers identifying the index of single tones cells. |
A raster without single tones cells. If rm=FALSE
, it returns a vector of numbers identifying the index of single tones cells.
The value assigned to single tone cells is picked from one of the four neighbouring cells, selected at random.
library(terra) m = matrix(0, 33, 33) r = rast(m) ext(r) = c(0, 10, 0, 10) patchSize = 500 ## Make a patch and introduce a single tone cell r = makePatch(r, patchSize, spt=578, rast=TRUE) r[578] = 0 plot(r) ## Now remove it plot( rmSingle(r) ) ## Single tones can be identified but not removed: rmSingle(r, rm = FALSE)
library(terra) m = matrix(0, 33, 33) r = rast(m) ext(r) = c(0, 10, 0, 10) patchSize = 500 ## Make a patch and introduce a single tone cell r = makePatch(r, patchSize, spt=578, rast=TRUE) r[578] = 0 plot(r) ## Now remove it plot( rmSingle(r) ) ## Single tones can be identified but not removed: rmSingle(r, rm = FALSE)