| calc_ndvi | R Documentation |
Computes the Normalized Difference Vegetation Index (NDVI) directly from
near-infrared (nir) and red (red) bands or numeric vectors.
calc_ndvi(nir, red)
nir |
Near-infrared band ( |
red |
Red band ( |
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.
A single-layer terra::SpatRaster (with layer name "NDVI")
or a numeric vector matching input dimensions.
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.
geo_index, calc_savi, calc_evi, index_registry
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.