calc_ndvi: Calculate Normalized Difference Vegetation Index (NDVI)

View source: R/calc_indices.R

calc_ndviR Documentation

Calculate Normalized Difference Vegetation Index (NDVI)

Description

Computes the Normalized Difference Vegetation Index (NDVI) directly from near-infrared (nir) and red (red) bands or numeric vectors.

Usage

calc_ndvi(nir, red)

Arguments

nir

Near-infrared band (terra::SpatRaster or numeric vector/matrix).

red

Red band (terra::SpatRaster or numeric vector/matrix).

Details

NDVI = \frac{NIR - RED}{NIR + RED}

Description & Purpose: NDVI is the most widely used remote sensing index for monitoring vegetation greenness, photosynthetic activity, and canopy vigor. Chlorophyll pigments in green leaves absorb red light strongly, while the spongy mesophyll structure scatters near-infrared light.

Direct Band Usage vs geo_index(): While geo_index(image, "NDVI") handles multi-band raster extraction and band mapping automatically, calc_ndvi() is a direct, lower-level computation function that works on:

  • Individual single-layer terra::SpatRaster objects (e.g. nir = img[["nir"]], red = img[["red"]]).

  • Standard R numeric vectors, scalars, or matrices.

Value Range & Interpretation:

  • 0.6 to 0.9: Dense, healthy green vegetation (forests, mature crops).

  • 0.2 to 0.5: Moderate to sparse vegetation (grasslands, shrublands, young crops).

  • 0.0 to 0.1: Bare soil, rock, sand, impervious urban areas.

  • < 0.0: Water bodies, snow, ice, and clouds.

Value

A single-layer terra::SpatRaster (with layer name "NDVI") or a numeric vector matching input dimensions.

References

Rouse, J. W., Haas, R. H., Schell, J. A., & Deering, D. W. (1974). Monitoring the vernal advancement and retrogradation (Green wave effect) of natural vegetation. NASA/GSFC Type III Final Report, Greenbelt, MD.

See Also

geo_index, calc_savi, calc_evi, index_registry

Examples

library(terra)

# --- Example 1: Direct calculation on numeric values ---
calc_ndvi(nir = 0.8, red = 0.2)

# Vectorized computation on numeric vectors:
nirs <- c(0.8, 0.5, 0.1, 0.02)
reds <- c(0.1, 0.3, 0.1, 0.05)
calc_ndvi(nir = nirs, red = reds)

# --- Example 2: Calculation on extracted SpatRaster layers ---
img <- get_example_data()
ndvi_rast <- calc_ndvi(nir = img[["nir"]], red = img[["red"]])
print(ndvi_rast)


GeoIndexR documentation built on Oct. 10, 2026, 5:08 p.m.