Database Reference
In-Depth Information
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() methodiseasytousebutlimitedtooperating
onatmosttworasterbands.Thisrestrictsthe ST_MapAlgebra() function'suseful-
ness for processes that require more than two input raster bands, such as Normal-
ized Difference Vegetation Index ( NDVI ) and Enhanced Vegetation Index ( EVI ).
Thereisavariantof ST_MapAlgebra() designedtosupportanunlimitednumberof
inputrasterbands.Insteadoftakinganexpression,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. Addition-
ally,thisvariantof ST_MapAlgebra() permitsoperationsonneighborhoods(setsof
pixels around a center pixel).
PostGIScomeswithasetofready-to-use ST_MapAlgebra() callbackfunctions.All
ofthesefunctionsareintendedforneighborhoodcalculations,suchascomputingthe
average value of a neighborhood or interpolating empty pixel values.
Getting ready
WewillusetheMODISrastertocomputetheEVI. EVI isathree-bandoperationcon-
sistingofthered,blue,andnear-infraredbands.Todoa ST_MapAlgebra() opera-
tiononthreebands,PostGIS2.1orahigherversionisrequired.IfyouhavePostGIS
2.0, a two-band EVI version is provided after we discuss the three-band variant.
How to do it...
Touse ST_MapAlgebra() onmorethantwobands,wemustusethecallbackfunc-
tionvariant.Thismeansweneedtocreateacallbackfunction.Callbackfunctionscan
bewritteninanyPostgreSQLPLlanguage,suchasPL/pgSQLorPL/R.Ourcallback
functionsareallwritteninPL/pgSQLasthislanguageisalwaysincludedwithabase
PostgreSQL installation.
Search WWH ::




Custom Search