vegIndex,GRaster-method | R Documentation |
This function calculates one of many types of vegetation indices from a raster with four bands representing blue (B), green (G), red (R), and near infrared (NIR), plus possibly channels 5 and 7. The function requires rasters that represent surface reflectance, so should have values that fall in the range 0 to 1, unless they are digital number rasters (e.g., integers in the range 0 to 255). If digital number format is used, then the bits
argument should be defined.
## S4 method for signature 'GRaster'
vegIndex(
x,
index = "NDVI",
r = NULL,
g = NULL,
b = NULL,
nir = NULL,
b5 = NULL,
b7 = NULL,
soilSlope = NULL,
soilIntercept = NULL,
soilNR = 0.08,
bits = NULL
)
x |
A |
index |
Character or character vector: The vegetation index or indices to calculate. You can find a list of available indices using fastData("vegIndices") (also see vegIndices). The first column, "
Note: A near-comprehensive table of indices can be found on the Index Database: A Database for Remote Sensing Indices. |
r , g , b , nir |
Numeric or character: Index or |
b5 , b7 |
Numeric or character: Index of names of the layers representing bands 5 and 7. These are used only for GVI and PVI. Values must be in the range from 0 to 1 or integers. |
soilSlope , soilIntercept , soilNR |
Numeric: Values of the soil slope, intercept, and soil noise reduction factor (0.08, by default). Used only for calculation of MSAVI. |
bits |
Either |
A GRaster
.
GRASS manual page for module i.vi
(see grassHelp("i.vi")
)
if (grassStarted()) {
# Setup
library(terra)
# Elevation raster, rivers vector
madLANDSAT <- fastData("madLANDSAT")
# Convert a SpatRaster to a GRaster:
landsat <- fast(madLANDSAT)
# See available vegetation indices:
vegIndices
# Normalized Difference Vegetation Index and Enhanced Vegetation Index:
indices <- c("ndvi", "evi")
vi <- vegIndex(landsat, index = indices, r = 1, b = 3, nir = 4, bits = 8)
plot(vi)
# All indices using R and NIR:
rnir <- vegIndex(landsat, index = "rnir", r = 1, nir = 4, bits = 8)
# Note: Some values are highly skewed, likely due to cloud cover and other
# anomalies that should be corrected.
plot(rnir)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.