Skip to contents

Compute or extract an index layer from a multi-band mosaic raster using gdal_calc.py (https://gdal.org/programs/gdal_calc.html). This requires a Python and GDAL installation.

Usage

mosaic_index2(
  mosaic,
  index = "B",
  r = 3,
  g = 2,
  b = 1,
  re = 4,
  nir = 5,
  plot = TRUE,
  python = Sys.which("python.exe"),
  gdal = Sys.which("gdal_calc.py")
)

Arguments

mosaic

A mosaic of class SpatRaster, generally imported with mosaic_input().

index

A character value (or a vector of characters) specifying the target mode for conversion to a binary image. Use pliman_indexes_rgb() and pliman_indexes_me() to see the available RGB and multispectral indexes, respectively. Users can also calculate their own index using R, G, B, RE, NIR, SWIR, and TIR bands (eg., index = "R+B/G") or using the names of the mosaic's layers (ex., "(band_1 + band_2) / 2").

r, g, b, re, nir

The red, green, blue, red-edge, and near-infrared bands of the image, respectively. By default, the function assumes a BGR as input (b = 1, g = 2, r = 3). If a multispectral image is provided up to seven bands can be used to compute built-in indexes. There are no limitation of band numbers if the index is computed using the band name.

plot

Plot the computed index? Defaults to TRUE.

python

The PATH for python.exe

gdal

The PATH for gdal_calc.py

Value

An index layer extracted/computed from the mosaic raster.

Examples

if(interactive() & (Sys.which('python.exe') != '' ) & (Sys.which('gdal_calc.py') != '' )){
library(pliman)
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
names(mosaic) <- "R"
elev2 <- mosaic_index2(mosaic, "R * 5", plot = FALSE)
oldpar <- par(no.readonly=TRUE)
mosaic_plot(mosaic)
mosaic_plot(elev2)
par(mfrow=c(1,2))
}