Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt

Use this file to discover all available pages before exploring further.

Apply a map algebra script on a raster. 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. RS_MapAlgebra is backed by Jiffle and can be compiled to Java bytecode for execution. For guidance on scripting for map algebra, refer to the Jiffle language summary. RS_MapAlgebra
The RS_MapAlgebra function can cast the output raster to a different data type specified by pixelType:
  • If pixelType is smaller than the input raster data type, narrowing casts will be performed, which may result in loss of data.
  • If pixelType is larger, widening casts will retain data accuracy.
  • If pixelType matches the input raster data type, no casting occurs.
This allows controlling the output pixel data type. Users should consider potential precision impacts when coercing to a smaller type.

Signatures

Single raster input

RS_MapAlgebra(rast: Raster, pixelType: String, script: String)
RS_MapAlgebra(rast: Raster, pixelType: String, script: String, noDataValue: Double)
RS_MapAlgebra(rast: Raster, pixelType: String, script: String, noDataValue: Double, numBands: Int)

Two raster inputs

RS_MapAlgebra(rast0: Raster, rast1: Raster, pixelType: String, script: String, noDataValue: Double)
RS_MapAlgebra(rast0: Raster, rast1: Raster, pixelType: String, script: String, noDataValue: Double, numBands: Int)

Parameters

rast
Raster
required
The input raster to apply the map algebra expression to. In the script, the rast variable is bound to this raster.
rast0
Raster
required
The first raster to apply the map algebra expression to (for two raster input signatures).
rast1
Raster
required
The second raster to apply the map algebra expression to (for two raster input signatures).
pixelType
String
required
The data type of the output raster. Accepts 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
String
required
The map algebra script written in Jiffle. The rast variable (or rast0/rast1 for two raster inputs) is bound to the input raster(s), and the out variable is bound to the output raster. Use bracket notation to access bands, e.g. rast[0] for the first band.
noDataValue
Double
The nodata value of the output raster. null is allowed.
numBands
Int
The number of bands in the output raster. When specified, the output bands can be referenced in the script using out[0], out[1], etc.

Return type

The resulting raster.

Examples

NDVI calculation

Calculate the NDVI of a raster with 4 bands (R, G, B, NIR):
SELECT RS_MapAlgebra(rast, 'D', 'out = (rast[3] - rast[0]) / (rast[3] + rast[0]);') AS ndvi FROM raster_table
+--------------------+
|              raster|
+--------------------+
|GridCoverage2D["g...|
+--------------------+

Two raster inputs

SELECT RS_MapAlgebra(rast0, rast1, 'D', 'out = rast0[0] * 0.5 + rast1[0] * 0.5;', null) FROM raster_table

Multi-band output

SELECT RS_MapAlgebra(rast, 'D', 'out[0] = rast[0] - rast[1]; out[1] = rast[0] + rast[1];', null, 2) FROM raster_table