require(terra)
p <- system.file("exdat", package = "rassta")
# Single-layer SpatRaster of stratification units
fsu <- list.files(path = p, pattern = "strata2.tif", full.names = TRUE)
su <- terra::rast(fsu)
# Define the structure of the stratification units' numeric code
code <- list(geology = c(1,1), climate = c(2,2), topography = c(3,3))
# Multi-layer SpatRaster of spatial signatures of classification units
fsig <- list.files(path = p, pattern = "geology_|climate_|topography_",
full.names = TRUE
)
sig <- terra::rast(fsig)
# Calculate landscape similarity to stratification units
landsim <- similarity(su.rast = su, su.code = code, sig.rast = sig)
# Plot some landscape similarities
# if(interactive()){plot(landsim$landsim[[c(1,10,12,14)]],
# col = hcl.colors(100, "Oslo", rev = TRUE)
# )}
#-------
# A note on the numeric code of stratification units
# For a given stratification unit, the structure of its corresponding numeric
# code indicates: (1) the landscape factors and/or factor scales that were
# accounted for when creating the stratification unit, and (2) the numeric id
# of the classification unit from each landscape factor/factor scale.
# Consider the following numeric code structure:
su.code <- list(geology = c(1,1), climate = c(2,2), topography = c(3,4))
# The stratification units are composed of classification units from...
# ...three landscape factors: geology, climate, and topography
names(su.code)
# For geology, the classification units are represented by the first...
# ...digit in the numeric code
su.code$geology
# For climate, the classification units are represented by the second...
# ...digit in the numeric code
su.code$climate
# For topography, the classification units are represented by the third...
# ...and fourth digit in the numeric code
su.code$topography
# Thus, the numeric code of the stratification units 1101 and 2410 means:
su <- c(1101, 2410)
su[1] # 'geology' = 1, 'climate' = 1, and 'topography' = 1
su[2] # 'geology' = 2, 'climate' = 4, and 'topography' = 10
Run the code above in your browser using DataLab