Uploaded image for project: 'Apache Sedona'
  1. Apache Sedona
  2. SEDONA-361

Add RS_MapAlgebra for performing map algebra operations using simple expressions

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.5.0

    Description

      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. 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:

      SELECT RS_MapAlgebra(rast, 'D', 'out = (rast[3] - rast[0]) / (rast[3] + rast[0]);') as ndvi FROM raster_table
      

      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.

      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
      

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kontinuation Kristin Cowalcijk
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m