## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----load---------------------------------------------------------------------
library(GeoIndexR)
library(terra)

# Load synthetic 6-band multispectral raster
img <- get_example_data()
print(img)
names(img)

## ----mapping------------------------------------------------------------------
# View pre-configured Sentinel-2 bands
band_mapping("sentinel2")

# View pre-configured Landsat 8/9 bands
band_mapping("landsat8")

## ----custom_map---------------------------------------------------------------
my_mapping <- c(
  blue  = "blue",
  green = "green",
  red   = "red",
  nir   = "nir",
  swir  = "swir1"
)

## ----compute------------------------------------------------------------------
indices <- geo_indices(
  image   = img,
  indices = c("NDVI", "NDWI", "NDBI", "SAVI", "BSI"),
  bands   = my_mapping
)

print(indices)
names(indices)

## ----summary------------------------------------------------------------------
stats <- index_summary(indices)
print(stats)

## ----plotting, fig.width=6, fig.height=5--------------------------------------
# Visualizing NDVI
plot_index(indices, index = "NDVI")

