ST_SYMDIFFERENCE scalar function

The ST_SYMDIFFERENCE function takes two geometry objects as input parameters and returns the geometry object that is the symmetrical difference of the two geometries. The symmetrical difference is the non-intersecting part of the two specified geometries.

If the geometries are equal, an empty geometry is returned. The resulting geometry is represented in the most appropriate spatial type.

If geometry1 or geometry2 is null, the result is the null value. If geometry1 and geometry2 are empty, an empty geometry is returned. If only one of geometry1 and geometry2 is empty, the other geometry is returned.

Read syntax diagramSkip visual syntax diagramST_SYMDIFFERENCE(geometry1,geometry2)
geometry1
A value of type ST_GEOMETRY or one of its subtypes that represents the first geometry to compute the symmetrical difference with geometry2.
geometry2
A value of type ST_GEOMETRY or one of its subtypes that represents the second geometry to compute the symmetrical difference with geometry1.

The result of the function is ST_GEOMETRY.

Example

Find the symmetrical difference of two polygons.


SELECT QSYS2.ST_ASTEXT(QSYS2.ST_SYMDIFFERENCE
                           (QSYS2.ST_POLYGON('polygon((10 10,10 20,20 20,20 10,10 10))'),
                            QSYS2.ST_POLYGON('polygon((30 30,30 50,50 50,50 30,30 30))')))
                                        AS SYMMETRICAL_DIFFERENCE
  FROM SYSIBM.SYSDUMMY1;
Results:

SYMMETRICAL_DIFFERENCE
-----------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION (POLYGON ((10.0 10.0, 20.0 10.0, 20.0 20.0, 10.0 20.0, 10.0 10.0)), 
                    POLYGON ((30.0 30.0, 50.0 30.0, 50.0 50.0, 30.0 50.0, 30.0 30.0)))