Returns the parts of two geometry objects that do not overlap.
Syntax
geometry ST_SymDifference(geometry geomA, geometry geomB);Parameters
| Parameter | Description |
|---|---|
geomA | The first input geometry object. |
geomB | The second input geometry object. |
Usage notes
GeometryCollection not supported. Passing a GeometryCollection as either argument is not supported.
3D objects are supported, but Z values are not recalculated. The function computes the symmetric difference using only X and Y coordinates. Z values in the output are taken from the original input geometries.
Examples
The following example computes the symmetric difference of two overlapping line strings. The two segments share the range X=1 to X=2, so the result excludes that overlap and returns the two non-shared portions as a MULTILINESTRING.
SELECT ST_AsText(ST_SymDifference('LINESTRING(0 0,2 0)'::geometry,'LINESTRING(1 0,3 0)'::geometry));Output:
st_astext
--------------------------------------
MULTILINESTRING((0 0,1 0),(2 0,3 0))
(1 row)What's next
ST_Difference — returns the part of geometry A that does not intersect geometry B (asymmetric)
ST_Intersection — returns the shared portion of two geometry objects
ST_Union — merges two geometry objects into one