ST_SymDifference

ST_SymDifference
Input geometries (blue and orange) and the resulting symmetric difference polygons (green).

ST_SymDifference takes two geometry columns and returns a geometry column. The output column contains the geometries that represent the portions of the input geometries that do not intersect. If one of the input geometry types is geometry, the output type will be the same. For all other cases the result geometry type will be the same as the input geometry type with the highest dimension.

FunctionSyntax
Pythonsym_difference(geometry1, geometry2)
SQLST_SymDifference(geometry1, geometry2)
ScalasymDifference(geometry1, geometry2)

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

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.sym_difference(ST.buffer("point", 5), "polygon")).st.plot()
Plotting example for ST_SymDifference
Plotted result for ST_SymDifference.

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.symDifference(ST.buffer($"point", 5), $"polygon").alias("sym_difference"))
              .withColumn("difference_area", F.round(ST.area($"sym_difference"),3))

df.show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+--------------------+---------------+
|      sym_difference|difference_area|
+--------------------+---------------+
|{"rings":[[[13,8]...|          92.35|
+--------------------+---------------+

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.