Map Algebra
Map algebra is a way to perform raster calculations using mathematical expressions. The expression can be a simple arithmetic operation or a complex combination of multiple operations. The expression can be applied to a single raster band or multiple raster bands. The result of the expression is a new raster. Apache Sedona provides two ways to perform map algebra operations:- Using the RS_MapAlgebra function.
- Using
RS_BandAsArrayand array based map algebra functions, such asRS_Add,RS_Multiply, etc.
RS_MapAlgebra function is more flexible and can be used to perform more complex operations. We’ll demonstrate both approaches to implementing commonly used map algebra operations below.
NDVI
The Normalized Difference Vegetation Index (NDVI) is a simple graphical indicator that can be used to analyze remote sensing measurements, typically, but not necessarily, from a space platform, and assess whether the target being observed contains live green vegetation or not. NDVI has become a de facto standard index used to determine whether a given area contains live green vegetation or not. The NDVI is calculated from these individual measurements as follows:RS_MapAlgebra function to do this:
out = (rast[3] - rast[0]) / (rast[3] + rast[0]);. The rast variable is always bound to the input raster, and
the out variable is bound to the output raster. Jiffle iterates over all the pixels in the input raster and executes the script for each pixel. the rast[3] and rast[0]
refers to the current pixel values of the near-infrared and red bands, respectively. The out variable is the current output pixel value.
The result of the RS_MapAlgebra function is a raster with a single band. The band is of type double, since we specified D as the pixelType argument.
We can implement the same NDVI calculation using the array based map algebra functions:
RS_BandAsArray function extracts the specified band of the input raster to an array of double, and the RS_Add, RS_Subtract, and RS_Divide functions perform the arithmetic operations on the arrays. The code using the array based map algebra functions is more verbose. However, there is a RS_NormalizedDifference function that can be used to calculate the NDVI more concisely:
RS_AddBandFromArray to add the array to a raster as a new band.
AWEI
The Automated Water Extraction Index (AWEI) is a spectral index that can be used to extract water bodies from remote sensing imagery. The AWEI is calculated from these individual measurements as follows:RS_MapAlgebra:

