Kristin Cowalcijk created SEDONA-361:
----------------------------------------

             Summary: Add RS_MapAlgebra for performing map algebra operations 
using simple expressions
                 Key: SEDONA-361
                 URL: https://issues.apache.org/jira/browse/SEDONA-361
             Project: Apache Sedona
          Issue Type: New Feature
            Reporter: Kristin Cowalcijk
             Fix For: 1.5.0


We'll add a new function {{RS_MapAlgebra}} for performing map algebra much 
easier. The {{RS_MapAlgebra(rast, pixelType, script, [noDataValue])}} function 
takes three to four arguments:
 * {{{}rast{}}}: The raster to apply the map algebra expression to.
 * {{{}pixelType{}}}: The data type of the output raster. This can be one of 
`D` (double), `F` (float), `I` (integer), `S` (short), `US` (unsigned short) or 
`B` (byte). If specified `NULL`, the output raster will have the same data type 
as the input raster.
 * {{{}script{}}}: The map algebra script.
 * {{{}noDataValue{}}}: (Optional) The nodata value of the output raster.

The map algebra script will be powered by 
[Jiffle|https://github.com/geosolutions-it/jai-ext/wiki/Jiffle]. It is feature 
rich and very efficient, since it compiles Jiffle script to java bytecode.

For example, NDVI calculation can be implemented using {{RS_MapAlgebra}} in 
this way:
{code:sql}
SELECT RS_MapAlgebra(rast, 'D', 'out = (rast[3] - rast[0]) / (rast[3] + 
rast[0]);') as ndvi FROM raster_table
{code}
Users can use any bands in the input raster, this is quite different from the 
map algebra function provided by PostGIS. The same NDVI calculation can be 
implemented using array-based map algebra functions already existing in Sedona, 
but much more verbose and error-prone.
{code:sql}
SELECT RS_Divide(
        RS_Subtract(RS_BandAsArray(rast, 1), RS_BandAsArray(rast, 4)),
        RS_Add(RS_BandAsArray(rast, 1), RS_BandAsArray(rast, 4))) as ndvi FROM 
raster_table
{code}
Currently, we'll only accept one raster as input. Since we can refer to 
multiple bands of the raster in the Jiffle script so it won't be a big blocker 
for implementing most of the real-world map algebra operations.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to