Performing advanced map-algebra operations
In a prior recipe, we used the expression-based map-algebra function ST_MapAlgebra()
to convert the PRISM pixel values to their true values. The expression-based
ST_MapAlgebra()
method is easy to use but limited to operating on at most two raster bands. This restricts the ST_MapAlgebra()
function's usefulness for processes that require more than two input raster bands, such as
Normalized Difference Vegetation Index (NDVI) and Enhanced Vegetation Index (EVI).
There is a variant of ST_MapAlgebra()
designed to support an unlimited number of input raster bands. Instead of taking an expression, this ST_MapAlgebra()
variant requires a callback function. This callback function is run for each set of input pixel values and returns either a new pixel value or NULL
for the output pixel. Additionally, this variant of ST_MapAlgebra()
permits operations on neighborhoods (sets of pixels around a center pixel).
PostGIS comes with a set of ready-to-use ST_MapAlgebra...