Skip to content

The RT_Calculator takes a string column and a raster column and returns a raster column. The string column represents a map algebra expression that will be run on the input raster. You can optionally specify 3 more raster columns if you want to run the expression on more raster inputs. The raster inputs in the expression can be defined as r1, r2, r3 and r4. The function expects the same number of bands on each raster, so if you are using raster inputs with mismatched band counts, you can use the RT_SelectBands function to specify the number of bands on each raster. The supported expressions are addition, subtraction, multiplication and division.

FunctionSyntax
Pythoncalculator(expression, raster1_col, raster2_col=None, raster3_col=None, raster4_col=None)
SQLcalculator(expression, raster1_col, raster2_col, raster3_col, raster4_col)
Scalacalculator(expression, raster1, raster2, raster3, raster4)

For more details, go to the GeoAnalytics Engine API reference for calculator.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10

from geoanalytics.raster import functions as RT
from pyspark.sql import functions as F

data = [([1,2,3,4], )]
df = spark.createDataFrame(data, ["pixels"]) \
     .withColumn("raster1", RT.create_raster("pixels", 2, 2, "float32"))

df_calculator = df.select(RT.calculator(F.lit("r1 * 10"), "raster1").alias("calculator"))
df_calculator.withColumn("calculator_pixels", RT.band_values("calculator", 1)).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+-------------------------+------------------------+
|calculator               |calculator_pixels       |
+-------------------------+------------------------+
|SqlRaster(1x2x2, Float32)|[10.0, 20.0, 30.0, 40.0]|
+-------------------------+------------------------+

Version table

ReleaseNotes

2.0.0

Python, SQL, and Scala functions introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.