Skip to content

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.

FunctionSyntax
Pythonmerge(rasters_col)
SQLRT_merge(rasters_col)
Scalamerge(rasterArray)

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

Examples

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

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)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+-------------------------+--------------------------------------------------------------------------------------+
|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

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.