
ST_Aggr_Union operates on a grouped DataFrame and returns the union of geometries in each group. All geometries are required to have the same type. For example having point, linestring, and polygon geometry types in the same column is not supported. You can group your DataFrame using DataFrame.groupBy() or with a GROUP BY clause in a SQL statement.
To find the union of geometries in each record, use ST_Union.
Function | Syntax |
---|---|
Python | aggr |
SQL | ST |
Scala | aggr |
For more details, go to the GeoAnalytics Engine API reference for aggr_union.
Examples
from geoanalytics.sql import functions as ST, Polygon
data = [
(1, Polygon([[[5,5],[12,5],[12,10],[5,10],[5,5]]])),
(1, Polygon([[[10,8],[14,8],[14,15],[10,15],[10,8]]])),
(2, Polygon([[[6,8],[20,8],[20,20],[6,20],[6,8]]]))
]
df = spark.createDataFrame(data, ["id", "polygon"])
df.groupBy("id")\
.agg(ST.aggr_union("polygon").alias("aggr_union"))\
.show(truncate=False)
+---+-----------------------------------------------------------------------------+
|id |aggr_union |
+---+-----------------------------------------------------------------------------+
|1 |{"rings":[[[5,5],[5,10],[10,10],[10,15],[14,15],[14,8],[12,8],[12,5],[5,5]]]}|
|2 |{"rings":[[[6,8],[20,8],[20,20],[6,20],[6,8]]]} |
+---+-----------------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0 | Python and SQL functions introduced |
1.5.0 | Scala function introduced |