The pattern-based spatial analysis makes it possible to compare spatial patterns between two datasets. This vignette shows how to do spatial patterns’ comparison on example datasets. Let’s start by attaching necessary packages:
Spatial patterns’ comparison requires two spatial objects. For this vignette, we read the
landcoverold = read_stars(system.file("raster/landcover2001.tif", package = "motif")) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif"))
The object created based on the first file,
landcoverold is a land cover of New Guinea in 2001.
landcoverold = droplevels(landcoverold) plot(landcoverold, key.pos = 4, key.width = lcm(5), main = NULL)
The second object,
landcover is a land cover of New Guinea in 2015.
Our goal here is to find areas with the largest changes of land cover spatial patterns.
Spatial patterns’ comparision can be done using the
lsp_compare() function. It expects two spatial objects, a type of spatial signature used (
"cove"), distance function to measure dissimilarity (change) between spatial patterns (
"dist_fun"). By default the whole area is compared, it can be changed with the
window argument. Here,
window = 100 means that the study area is be divided into local landscapes of 100 by 100 cells.
compare_1 = lsp_compare(landcover, landcoverold, type = "cove", dist_fun = "jensen-shannon", window = 100, threshold = 0.9) #> Metric: 'jensen-shannon' using unit: 'log2'.
The output is a
stars object with a
dist argument, with the value of 0 indicating no change, and larger values (up to 1) representing changes of a bigger magnitude.
Let’s see the local landscape with the largest change in a spatial pattern.
Its id is
2036, and its value of change (distance) is about 0.228. We can extract two maps using the
Visualization of this local landscape shows that about 1/3 of this area was covered by agriculture in 2001, but has only a few small areas of agriculture in 2015.
compare_1_2036 = droplevels(compare_1_2036) plot(compare_1_2036, main = "2001", key.pos = 4, key.width = lcm(5))
The motif package also allows for the comparing spatial patterns in irregular regions based on the user-provided polygons. It has an example spatial vector dataset,
ecoregions.gpkg, which contains terrestrial ecoregions for New Guinea from https://ecoregions2017.appspot.com/.
This dataset has 22 rows, where each row relates to one ecoregion. Each ecoregion is also related to a unique value in the
Comparision of spatial patterns for irregular local landscapes requires setting
window = ecoregions["id"].
compare_2 = lsp_compare(landcover, landcoverold, type = "cove", dist_fun = "jensen-shannon", window = ecoregions["id"], threshold = 0.9) #> Metric: 'jensen-shannon' using unit: 'log2'.
Spatial patterns of land cover stayed very similar for most of the ecoregions, with just two exceptions:
Let’s see the ecoregion with the largest change in a spatial pattern.
Its id is
18, and its value of change (distance) is about 0.006. We can extract two maps using the
The degree of change is distinctly smaller than in the first example above. Now, we can see the change from agriculture to forest mostly in the north-east of the ecoregion.
compare_2_18 = droplevels(compare_2_18) plot(compare_2_18, main = "2001", key.pos = 4, key.width = lcm(5))