Skip to contents

This function applies a forms_matrix to reclassify a SpatRaster object with 2 layers containing positive and negative overlooks.

Usage

forms_matrix_apply(
  x,
  rcl = forms_matrix_get(),
  positive = "positive",
  negative = "negative",
  ...
)

Arguments

x

SpatRaster containing two layers with names specified in positive and negative.

rcl

forms_matrix. Matrix to use for classification of x. Rows are "negative" and columns are "positive".

positive

Character. Layer name of positive count. Default: "positive".

negative

Character. Layer name of negative count. Default: "negative".

...

Additional arguments passed to terra::classify().

Value

A SpatRaster containing the classification result.

See also

Examples

library(terra)
library(rgeomorphon)

SEARCH = 7       # outer search radius (cells)
SKIP = 1         # inner skip radius (cells)
DIST = 0         # flatness distance (cells)
FLAT = 1         # flat angle threshold
MODE = "anglev1" # comparison mode

## classic volcano elevation data
data("volcano", package = "datasets")

# construct and georeference a SpatRaster object
dem <- terra::flip(terra::rast(volcano))
terra::crs(dem) <- terra::crs("EPSG:27200")
terra::ext(dem) <- c(2667400, 2668010, 6478700, 6479570)
names(dem) <- "Elevation (meters)"

res <- geomorphons(
    dem,
    search = SEARCH,
    skip = SKIP,
    dist = DIST,
    flat = FLAT,
    comparison_mode = MODE,
    forms = TRUE,
    ternary = TRUE,
    positive = TRUE,
    negative = TRUE
)

res2 <- terra::rast(lapply(c(4, 5, 6), function(n) {
  geomorphon_theme(
    forms_matrix_apply(
        x = res[[c("positive", "negative")]],
        rcl = forms_matrix_get(n)
    )
  )
}))
names(res2) <- c("forms4", "forms5", "forms6")

terra::plot(c(res, res2))