Returns the symmetric difference of two geometry objects — the portions of each geometry that do not overlap with the other.
Syntax
geometry ST_SymDifference(geometry geomA, geometry geomB)Parameters
| Parameter | Description |
|---|---|
geomA | The first geometry object. |
geomB | The second geometry object. |
Usage notes
GeometryCollection not supported. This function does not support
GeometryCollectionobjects.3D geometry support is partial. The function supports 3D geometries and preserves Z coordinates in the output, but the symmetric difference calculation uses only the X and Y coordinates. The output geometry object retains the original Z coordinates from the input.
Examples
The following example computes the symmetric difference of two overlapping line strings. The overlapping segment (1 0, 2 0) is excluded from the result; the non-overlapping segments from each input are returned as a MULTILINESTRING.
SELECT ST_AsText(
ST_SymDifference(
'LINESTRING(0 0, 2 0)'::geometry,
'LINESTRING(1 0, 3 0)'::geometry
)
);Output:
MULTILINESTRING((0 0,1 0),(2 0,3 0))
(1 row)What's next
ST_Difference — returns the part of geomA that does not intersect with geomB (asymmetric)
ST_Union — returns the union of two geometry objects
ST_Intersection — returns the portion shared by two geometry objects