You are on page 1of 2

PostGIS 1.5.

1 Manual
240 / 315

Description
Returns a geometry that represents the portions of A and B that do not intersect. It is called a symmetric difference because
ST_SymDifference(A,B) = ST_SymDifference(B,A). One can think of this as ST_Union(geomA,geomB) - ST_Intersection(A,B).
Performed by the GEOS module

Note
Do not call with a GeometryCollection as an argument

This method implements the OpenGIS Simple Features Implementation Specification for SQL 1.1. s2.1.1.3
This method implements the SQL/MM specification. SQL-MM 3: 5.1.21
This function supports 3d and will not drop the z-index. However it seems to only consider x y when doing the difference
and tacks back on the Z-Index

Examples

The original linestrings shown together


--Safe for 2d - symmetric difference of 2 linestrings
SELECT ST_AsText(
ST_SymDifference(
ST_GeomFromText(LINESTRING(50 100, 50 200)),
ST_GeomFromText(LINESTRING(50 50, 50 150))
)
);
st_astext
---------

The symmetric difference of the two linestrings

PostGIS 1.5.1 Manual


241 / 315

MULTILINESTRING((50 150,50 200),(50 50,50 100))

--When used in 3d doesnt quite do the right thing


SELECT ST_AsEWKT(ST_SymDifference(ST_GeomFromEWKT(LINESTRING(1 2 1, 1 4 2)),
ST_GeomFromEWKT(LINESTRING(1 1 3, 1 3 4))))
st_astext
-----------MULTILINESTRING((1 3 2.75,1 4 2),(1 1 3,1 2 2.25))

See Also
ST_Difference, ST_Intersection, ST_Union

7.9.19 ST_Union
Name
ST_Union Returns a geometry that represents the point set union of the Geometries.

Synopsis
geometry ST_Union(geometry set g1field);
geometry ST_Union(geometry g1, geometry g2);
geometry ST_Union(geometry[] g1_array);

Description
Output type can be a MULTI* , single geometry, or Geometry Collection. Comes in 2 variants. Variant 1 unions 2 geometries
resulting in a new geomety with no intersecting regions. Variant 2 is an aggregate function that takes a set of geometries and
unions them into a single ST_Geometry resulting in no intersecting regions.
Aggregate version: This function returns a MULTI geometry or NON-MULTI geometry from a set of geometries. The ST_Union()
function is an "aggregate" function in the terminology of PostgreSQL. That means that it operates on rows of data, in the same
way the SUM() and AVG() functions do.
Non-Aggregate version: This function returns a geometry being a union of two input geometries. Output type can be a MULTI*
,NON-MULTI or GEOMETRYCOLLECTION.
Note
ST_Collect and ST_Union are often interchangeable. ST_Union is in general orders of magnitude slower than
ST_Collect because it tries to dissolve boundaries and reorder geometries to ensure that a constructed Multi* doesnt
have intersecting regions.

Performed by the GEOS module.


NOTE: this function was formerly called GeomUnion(), which was renamed from "Union" because UNION is an SQL reserved
word.

Availability: 1.4.0 - ST_Union was enhanced. ST_Union(geomarray) was introduced and also faster aggregate collection in PostgreSQL. If you are using GEOS 3.1.0+ ST_Union will use the faster Cascaded Union algorithm described in http://blog.cleverelephant.ca/
2009/01/must-faster-unions-in-postgis-14.html
This method implements the OpenGIS Simple Features Implementation Specification for SQL 1.1. s2.1.1.3

You might also like