ST_Union

ST_Union
Three input polygons (green, orange, purple) and the resulting unioned polygon (blue).

ST_Union takes two or more geometry columns and returns a geometry column. The output column contains the geometries that represent the spatial union of the geometries in each row of the input columns. The geometry types of the input columns must be the same. To find the union of all geometries in a group or column use ST_Aggr_Union.

FunctionSyntax
Pythonunion(*geometries)
SQLST_Union(*geometries)
Scalaunion(geometries)

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

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

Python and SQL Examples

PythonPythonSQL
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
from geoanalytics.sql import functions as ST, Point, Polygon

df = spark.createDataFrame([(Point(8,8), Polygon([[[0,0],[10,0],[10,10],[0,10]]]),)], ["point", "polygon"])

df.select(ST.union(ST.buffer("point", 5), "polygon")).st.plot()
Plotting example for ST_Union
Plotted result for ST_Union.

Scala Example

Scala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import com.esri.geoanalytics.geometry._
import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}

case class GeometryRow(point: Point, polygon: Polygon)
val data = Seq(GeometryRow(Point(8, 8), Polygon(Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0))))

val df = spark.createDataFrame(data)
              .select(ST.union(ST.buffer($"point", 5), $"polygon").alias("union"))
              .withColumn("union_area", F.round(ST.area($"union"),3))

df.show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+--------------------+----------+
|               union|union_area|
+--------------------+----------+
|{"rings":[[[0,0],...|   135.417|
+--------------------+----------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.