This guide explains how to create mathematical expressions to calculate custom spectral indices in the RAVI plugin. It also provides practical examples and important tips to avoid common mistakes.

Available Bands

Sentinel-2 provides the following bands that you can use in your expressions:

Band (use it in the expression) Name Description Wavelength Spatial Resolution
B1 Coastal aerosol Coastal aerosol 443 nm 60 m
B2 Blue Blue 490 nm 10 m
B3 Green Green 560 nm 10 m
B4 Red Red 665 nm 10 m
B5 Red Edge 1 Red Edge 1 705 nm 20 m
B6 Red Edge 2 Red Edge 2 740 nm 20 m
B7 Red Edge 3 Red Edge 3 783 nm 20 m
B8 NIR Near Infrared 842 nm 10 m
B8A Narrow NIR Narrow Near Infrared 865 nm 20 m
B9 Water vapor Water vapor 940 nm 60 m
B11 SWIR 1 Shortwave Infrared 1 1610 nm 20 m
B12 SWIR 2 Shortwave Infrared 2 2190 nm 20 m

Supported Operators

Arithmetic Operators

Relational Operators

Logical Operators

Available Mathematical Functions

Expression Examples

NDVI (Normalized Difference Vegetation Index)

(B8 - B4) / (B8 + B4)

EVI (Enhanced Vegetation Index)

2.5 * ((B8 - B4) / (B8 + 6 * B4 - 7.5 * B2 + 1))

SAVI (Soil Adjusted Vegetation Index) with L=0.5

(1 + 0.5) * ((B8 - B4) / (B8 + B4 + 0.5))

NDRE (Normalized Difference Red Edge)

(B8 - B5) / (B8 + B5)

NDMI (Normalized Difference Moisture Index)

(B8 - B11) / (B8 + B11)

Conditional Expression

This expression calculates NDVI only when the red band (B4) is greater than 0.2. Otherwise, it returns 0:

(B4 > 0.2) ? ((B8 - B4) / (B8 + B4)) : 0

This expression calculates NDMI only when the SWIR1 band (B11) is greater than 0.1. Otherwise, it returns -1:

(B11 > 0.1) ? ((B8 - B11) / (B8 + B11)) : -1

Conditional Expression with Logical Operators

This expression calculates NDVI only when both the red band (B4) is greater than 0.2 and the NIR band (B8) is greater than 0.3. Otherwise, it returns 0:

(B4 > 0.2 && B8 > 0.3) ? ((B8 - B4) / (B8 + B4)) : 0

Important Tips

Attention

When creating complex expressions, test them incrementally to ensure they work as expected. Extreme values or division by zero can cause unexpected results.