knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
GeoIndexR is a modern, modular, and extensible R package for computing spectral and geospatial indices from multispectral raster data. Built natively on terra, GeoIndexR operates on SpatRaster objects and file paths while preserving all georeferencing, projection (CRS), resolution, and spatial extents.
Beyond standard indices, GeoIndexR features a secure custom formula engine (geo_index_custom()) enabling users to compute any mathematical expression on spectral bands with custom constants.
You can pass a loaded terra::SpatRaster or directly supply a file path character string:
library(GeoIndexR) library(terra) # Load synthetic 6-band multispectral image img <- get_example_data() print(img) names(img)
Bands can be resolved automatically by layer name, by layer position index (c(red = 3, nir = 4)), or using sensor presets (sensor = "sentinel2"):
# Band mapping by explicit role name bands_map <- c(red = "red", nir = "nir", blue = "blue")
Compute standard indices using geo_index():
ndvi <- geo_index(img, "NDVI", bands = bands_map) print(ndvi)
Use index_summary() to compute descriptive statistics including percentiles (q05, q25, q75, q95) and NA percentages:
summary_tbl <- index_summary(ndvi) print(summary_tbl)
Use plot_index() with thematic color palettes automatically matched to index categories (vegetation, water, urban, soil, snow):
plot_index(ndvi, "NDVI")
All outputs from GeoIndexR are standard terra::SpatRaster objects, ready for export:
writeRaster(ndvi, "NDVI_output.tif", overwrite = TRUE)
Compute your own formulas using geo_index_custom():
# Compute a custom ratio custom_ratio <- geo_index_custom( img, formula = "(nir - red) / (nir + red)", bands = c(red = "red", nir = "nir"), name = "MyCustomNDVI" ) print(custom_ratio) # Compute a custom parameterized index custom_veg <- geo_index_custom( img, formula = "G * (nir - red) / (nir + C1 * red - C2 * blue + L)", bands = c(blue = "blue", red = "red", nir = "nir"), params = list(G = 2.5, C1 = 6.0, C2 = 7.5, L = 1.0), name = "CustomEVI" ) print(custom_veg)
For scale-sensitive indices (such as EVI, SAVI, MSAVI, ARVI) where input data are stored as raw integer Digital Numbers (e.g. $[0, 10000]$ in Sentinel-2 L2A), specify scale_factor = 10000:
# Mock integer DN raster img_dn <- img * 10000 # Calculate EVI with proper scale factor conversion evi_scaled <- geo_index( img_dn, "EVI", bands = c(blue = "blue", red = "red", nir = "nir"), scale_factor = 10000 ) index_summary(evi_scaled)
Explore available indices, formulas, required bands, interpretations, and literature citations via index_registry():
reg <- index_registry(category = "vegetation") reg[, c("index", "name", "required_bands", "requires_reflectance")]
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.