RT_Merge takes an array column containing arrays of rasters and returns a raster column representing the single raster created by merging the rasters in each array. The input rasters must have the same number of bands. When rasters overlap, cell values are taken from the first raster in the array that contains valid data (non-NoData values) for that location.
This function is useful for creating mosaics from tiled rasters, combining images across extents, or consolidating multiple rasters into a single dataset.
| Function | Syntax |
|---|---|
| Python | merge(rasters |
| SQL | RT |
| Scala | merge(raster |
For more details, go to the GeoAnalytics Engine API reference for merge.
Examples
from geoanalytics.raster import functions as RT
data = [(list(range(16)), )]
df = spark.createDataFrame(data, ["pixels"]) \
.withColumn("raster", RT.set_extent(RT.srid(RT.create_raster("pixels", 4, 4, "float32"), 4326), xmin=-122.57, ymin=47.34, xmax=-121.77, ymax=48.14))
# Tiles the raster into an array of rasters
df_tile = df.withColumn("tiles", RT.tiles("raster", 2, 2))
# Merges the array of tiled rasters
df_merge = df_tile.select(RT.merge("tiles").alias("merge"))
df_merge.withColumn("merge_pixels", RT.band_values("merge", 1)).show(truncate=False)+-------------------------+--------------------------------------------------------------------------------------+
|merge |merge_pixels |
+-------------------------+--------------------------------------------------------------------------------------+
|SqlRaster(1x4x4, Float32)|[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0]|
+-------------------------+--------------------------------------------------------------------------------------+Version table
| Release | Notes |
|---|---|
2.0.0 | Python, SQL, and Scala functions introduced |