This vignette demonstrates a complete workflow for processing
multispectral satellite imagery using GeoIndexR and
terra:
library(GeoIndexR)
library(terra)
# Load synthetic 6-band multispectral raster
img <- get_example_data()
print(img)
#> class : SpatRaster
#> size : 10, 10, 6 (nrow, ncol, nlyr)
#> resolution : 10, 10 (x, y)
#> extent : 440000, 440100, 5410000, 5410100 (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 31N (EPSG:32631)
#> source(s) : memory
#> names : blue, green, red, nir, swir1, swir2
#> min values : 0.020686, 0.040375, 0.020125, 0.01012, 0.005325, 0.001571
#> max values : 0.198877, 0.248389, 0.348878, 0.841345, 0.542598, 0.44794
names(img)
#> [1] "blue" "green" "red" "nir" "swir1" "swir2"Satellite images often use sensor-specific band notations (such as
B02, B03, B04, B08
for Sentinel-2, or B2, B3, B4,
B5 for Landsat 8/9).
GeoIndexR supports sensor presets:
# View pre-configured Sentinel-2 bands
band_mapping("sentinel2")
#> coastal blue green red rededge1 rededge2 rededge3
#> "B01" "B02" "B03" "B04" "B05" "B06" "B07"
#> nir nir2 rededge4 watervapor cirrus swir1 swir2
#> "B08" "B8A" "B8A" "B09" "B10" "B11" "B12"
#> swir
#> "B11"
# View pre-configured Landsat 8/9 bands
band_mapping("landsat8")
#> coastal blue green red nir swir1 swir2 pan
#> "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8"
#> cirrus thermal1 thermal2 thermal swir
#> "B9" "B10" "B11" "B10" "B6"If your image layers use non-standard names, you can pass a custom named vector:
Compute a multi-index suite covering vegetation, water, urban built-up, and soil:
indices <- geo_indices(
image = img,
indices = c("NDVI", "NDWI", "NDBI", "SAVI", "BSI"),
bands = my_mapping
)
print(indices)
#> class : SpatRaster
#> size : 10, 10, 5 (nrow, ncol, nlyr)
#> resolution : 10, 10 (x, y)
#> extent : 440000, 440100, 5410000, 5410100 (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 31N (EPSG:32631)
#> source(s) : memory
#> names : NDVI, NDWI, NDBI, SAVI, BSI
#> min values : -0.551249, -0.843134, -0.661868, -0.113622, -0.607442
#> max values : 0.920312, 0.724656, 0.316349, 0.863868, 0.303357
names(indices)
#> [1] "NDVI" "NDWI" "NDBI" "SAVI" "BSI"Use index_summary() to inspect the distributions across
all computed layers:
stats <- index_summary(indices)
print(stats)
#>
#> === GeoIndexR Spectral Summary ===
#>
#> index min max mean median sd q05 q25 q75 q95
#> NDVI -0.5512 0.9203 0.3017 0.1253 0.4892 -0.4504 -0.0480 0.8526 0.9068
#> NDWI -0.8431 0.7247 -0.2079 -0.2693 0.5404 -0.8046 -0.7491 0.3908 0.6368
#> NDBI -0.6619 0.3163 -0.2674 -0.4134 0.3285 -0.6408 -0.5491 0.1010 0.2810
#> SAVI -0.1136 0.8639 0.3111 0.1048 0.3730 -0.0607 -0.0130 0.7345 0.8486
#> BSI -0.6074 0.3034 -0.2654 -0.4389 0.3237 -0.5816 -0.5097 0.1576 0.2644
#> na_pct total_cells
#> 1 100
#> 1 100
#> 1 100
#> 1 100
#> 1 100plot_index() applies scientifically tailored palettes
based on index categories:
terra::writeRasterSince all outputs returned by GeoIndexR are standard
terra::SpatRaster objects with full CRS and geotransform
preservation, saving results to GeoTIFF or COG is simple:
# Export the multilayer raster to GeoTIFF
terra::writeRaster(indices, "computed_indices.tif", overwrite = TRUE)This ensures complete compatibility with GDAL, QGIS, ArcGIS, Python rasterio, and web mapping services.