GeoTrellis Operations

GeoTrellis provides a rich set of Map Algebra operations and other tile processing features that can be used with RasterFrames via Spark’s UDF support.

Here’s an example creating a UDFs to invoke the equalize transformation on each tile in a RasterFrame, and then compute the resulting per-tile mean of it.

scala> import geotrellis.raster.equalization._
import geotrellis.raster.equalization._

scala> val equalizer = udf((t: Tile) => t.equalize())
equalizer: org.apache.spark.sql.expressions.UserDefinedFunction = UserDefinedFunction(<function1>,org.apache.spark.sql.gt.types.TileUDT@47c06ea9,Some(List(org.apache.spark.sql.gt.types.TileUDT@47c06ea9)))

scala> val equalized = rf.select(equalizer($"tile") as "equalized")
equalized: org.apache.spark.sql.DataFrame = [equalized: rf_tile]

scala> equalized.select(tileMean($"equalized") as "equalizedMean").show(5, false)
+------------------+
|equalizedMean     |
+------------------+
|32634.257767197705|
|32777.45174876396 |
|32776.88976377953 |
|32775.86650796558 |
|32779.3839956052  |
+------------------+
only showing top 5 rows

Here’s an example downsampling a tile and rendering each tile as a matrix of numerical values.

scala> val downsample = udf((t: Tile) => t.resample(4, 4))
downsample: org.apache.spark.sql.expressions.UserDefinedFunction = UserDefinedFunction(<function1>,org.apache.spark.sql.gt.types.TileUDT@47c06ea9,Some(List(org.apache.spark.sql.gt.types.TileUDT@47c06ea9)))

scala> val downsampled = rf.select(renderAscii(downsample($"tile")) as "minime")
downsampled: org.apache.spark.sql.DataFrame = [minime: string]

scala> downsampled.show(5, false)
+-------------------+
|minime             |
+-------------------+
|∘∘∘∘
∘∘∘∘
∘∘∘∘
∘∘∘∘|
|.%*+
=@=@
#+:#
:-  |
|-:*+
.=-.
 +@#
%.@#|
|. @#
::=+
%@#=
 +*-|
|:#*=
 .-:
@+% 
#+@=|
+-------------------+
only showing top 5 rows