Compute or extract an index layer from a multi-band mosaic raster.
Arguments
- mosaic
A mosaic of class
SpatRaster
, generally imported withmosaic_input()
.- index
The index to use for the index view. Defaults to "B".
- r
The layer for the Red band (default: 3).
- g
The layer for the Green band (default: 2).
- b
The layer for the Blue band (default: 1).
- re
The layer for the Red-edge band (default: 4).
- nir
The layer for the Near-infrared band(default: 5).
Details
This function computes or extracts an index layer from the input
mosaic raster based on the specified index name. If the index is not found
in the package's predefined index list (see image_index()
for more
details), it attempts to compute the index using the specified band
indices. The resulting index layer is returned as an SpatRaster
object.
Examples
library(pliman)
library(terra)
#> terra 1.7.55
#>
#> Attaching package: 'terra'
#> The following object is masked from 'package:pliman':
#>
#> distance
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
confusion <-
matrix(rnorm(90*95, 100, 30),
nrow = nrow(mosaic),
ncol = ncol(mosaic))
confusion <- mosaic_input(confusion)
terra::ext(confusion) <- terra::ext(mosaic)
terra::crs(confusion) <- terra::crs(mosaic)
names(confusion) <- "confusion"
two_layers <- c(mosaic, confusion)
final <- mosaic_index(two_layers, "B+R", b = 1, r = 2)
#> Index 'B+R' is not available. Trying to compute your own index.
mosaic_view(mosaic_input(final), viewer = "base")