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 function to specify the number of bands on each raster.
The supported expressions are addition, subtraction, multiplication and division.
| Function | Syntax |
|---|---|
| Python | calculator(expression, raster1 |
| SQL | calculator(expression, raster1 |
| Scala | calculator(expression, raster1, raster2, raster3, raster4) |
For more details, go to the GeoAnalytics Engine API reference for calculator.
Examples
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)+-------------------------+------------------------+
|calculator |calculator_pixels |
+-------------------------+------------------------+
|SqlRaster(1x2x2, Float32)|[10.0, 20.0, 30.0, 40.0]|
+-------------------------+------------------------+Version table
| Release | Notes |
|---|---|
2.0.0 | Python, SQL, and Scala functions introduced |