## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7.5,
  fig.height = 5.5,
  out.width = "100%",
  dpi = 72
)

## ----data---------------------------------------------------------------------
library(landform)
library(terra)

dem <- malta_dtm()
dem
plot(dem, col = hcl.colors(50, "Terrain 2"), main = "Malta DTM (m)")

## ----tpi, fig.height = 4------------------------------------------------------
t_small <- tpi(dem, scale = 120, units = "map", shape = "circle", std = "none")
t_large <- tpi(dem, scale = 1000, units = "map", shape = "circle", std = "none")
rng <- c(-30, 30)
plot(c(t_small, t_large), range = rng,
     col = hcl.colors(100, "Blue-Red 3"),
     main = c("TPI (m), 120 m radius", "TPI (m), 1000 m radius"))

## ----std, fig.height = 4------------------------------------------------------
g <- landform(dem, scale = 9, plot = FALSE)
l <- landform(dem, scale = 9, std = "local", plot = FALSE)
par(mfrow = c(1, 2))
plot(g$classes, main = "Global standardisation", legend = FALSE,
     mar = c(1, 1, 2, 1), axes = FALSE)
plot(l$classes, main = "Local standardisation", legend = FALSE,
     mar = c(1, 1, 2, 1), axes = FALSE)
par(mfrow = c(1, 1))

## ----std-table----------------------------------------------------------------
data.frame(class = g$stats$class,
           global = round(g$stats$percent, 1),
           local = round(l$stats$percent, 1))

## ----sp-----------------------------------------------------------------------
sp <- landform(dem, scale = 9)
sp

## ----sp-slopeshade------------------------------------------------------------
plot(sp, shade = "slope")

## ----sp-scale-----------------------------------------------------------------
sp_broad <- landform(dem, scale = 600, units = "map", shape = "circle")

## ----lf-----------------------------------------------------------------------
lf <- landform(dem, class.type = "landform.classification",
               sn = 200, ln = 1000, units = "map", shape = "circle",
               shade = "slope")

## ----lf-tpi, fig.height = 4---------------------------------------------------
plot(lf, what = "tpi", shade = "slope")

## ----stats--------------------------------------------------------------------
summary(lf)
plot(lf, what = "area")

## ----segregate----------------------------------------------------------------
layers <- class_layers(lf)
names(layers)
plot(layers[["Mountain Tops, High Ridges"]], legend = FALSE,
     col = c("grey90", "#6A3D9A"), main = "Mountain Tops, High Ridges")

## ----legacy, eval = FALSE-----------------------------------------------------
# landform(dem, scale = 9, std = "local", centre = TRUE)

