
Calculate water indices including both NDWI variants
Source:R/03-water-indices.R
calculate_water_index.RdCalculate various water indices including NDWI (McFeeters 1996), MNDWI (Xu 2006), and NDMI (Gao 1996) for water body detection and moisture content. Updated formulas based on latest research and satellite missions (2024).
Usage
calculate_water_index(
green,
nir,
swir1 = NULL,
index_type = "NDWI",
clamp_range = NULL,
mask_invalid = TRUE,
verbose = FALSE
)Arguments
- green
Green band SpatRaster or file path
- nir
NIR band SpatRaster or file path
- swir1
SWIR1 band SpatRaster or file path (for MNDWI, NDMI)
- index_type
Index type: "NDWI", "MNDWI", "NDMI", "MSI", "NDII", "WI", "SRWI", "LSWI"
- clamp_range
Optional range to clamp output values
- mask_invalid
Mask invalid/extreme values
- verbose
Print progress messages
Details
Available water indices with their specific applications:
Primary Water Detection Indices:
NDWI (McFeeters 1996): (Green - NIR) / (Green + NIR) - Use: Open water body detection, flood mapping - Range: Values from -1 to 1, water bodies typically > 0.3 - Pros: Simple, effective for clear water - Cons: Sensitive to built-up areas, can overestimate water
MNDWI (Xu 2006): (Green - SWIR1) / (Green + SWIR1) - Use: Enhanced water detection, urban water bodies - Range: Values from -1 to 1, water bodies typically > 0.5 - Pros: Better separation of water from built-up areas - Cons: Requires SWIR band, less effective with turbid water
Vegetation Moisture Indices:
NDMI (Gao 1996): (NIR - SWIR1) / (NIR + SWIR1) - Use: Vegetation water content, drought monitoring - Range: Values from -1 to 1, higher values = more water content - Application: Agriculture, forest fire risk assessment
MSI: SWIR1 / NIR - Moisture Stress Index - Use: Plant water stress detection - Range:
[0, 5+], lower values = higher moistureNDII: (NIR - SWIR1) / (NIR + SWIR1) - Same as NDMI - Use: Alternative name for NDMI, vegetation moisture
Examples
if (FALSE) { # \dontrun{
# These examples require external data files not included with the package
# Original NDWI for water body detection
ndwi <- calculate_water_index(green_band, nir_band, index_type = "NDWI")
# Modified NDWI for enhanced water detection (requires SWIR1)
mndwi <- calculate_water_index(green_band, nir_band, swir1_band, index_type = "MNDWI")
# NDMI for vegetation moisture monitoring
ndmi <- calculate_water_index(green_band, nir_band, swir1_band, index_type = "NDMI")
# With quality control
water_index <- calculate_water_index(
green = "green.tif",
nir = "nir.tif",
swir1 = "swir1.tif",
index_type = "MNDWI",
clamp_range = c(-1, 1),
mask_invalid = TRUE,
verbose = TRUE
)
} # }