Skip to main content
Apply a map algebra script on a raster. RS_MapAlgebra

Signatures

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

Parameters

rast0
Raster
The rast0 value.
rast1
Raster
The rast1 value.
pixelType
String
required
The pixel type value.
script
String
required
The script value.
noDataValue
Double
The NoData value to use for pixels outside the raster extent.
raster
Raster
The input raster.

Return type

The resulting raster.

Examples

Calculate the NDVI of a raster with 4 bands (R, G, B, NIR):
-- Assume that the input raster has 4 bands: R, G, B, NIR
-- rast[0] refers to the R band, rast[3] refers to the NIR band.
SELECT RS_MapAlgebra(rast, 'D', 'out = (rast[3] - rast[0]) / (rast[3] + rast[0]);') AS ndvi FROM raster_table
+--------------------+
|              raster|
+--------------------+
|GridCoverage2D["g...|
+--------------------+
Spark SQL Example for two raster input RS_MapAlgebra:
RS_MapAlgebra(rast0, rast1, 'D', 'out = rast0[0] * 0.5 + rast1[0] * 0.5;', null)
For more details and examples about RS_MapAlgebra, please refer to the Map Algebra documentation. To learn how to write map algebra script, please refer to Jiffle language summary.