How the ST_Union Geometry Tool works, and what it assumes
ST_Union merges geometries into one that covers every point of every input, with the boundaries between them removed. PostGIS has two forms, and the page supports both: with two inputs it computes ST_Union(A, B); with only Geometry A it dissolves every part of A into one geometry, which is what the aggregate SELECT ST_Union(geom) FROM parcels does over a set of rows.
Pasting a FeatureCollection into Geometry A is the quickest way to dissolve a layer. Areas that touch or overlap merge into single polygons, and separate ones stay as parts of a MultiPolygon. A union also repairs one kind of invalid geometry: a MultiPolygon whose parts overlap comes back as a valid geometry. Self-intersecting rings are a different fault, which is refused with its location.
Merging mixed kinds of geometry is allowed. Points and lines that fall inside a polygon are absorbed by it; anything outside stays as it is, so the result may be a GeometryCollection. The merged area is measured geodesically for longitude and latitude.
Where this comes up in GIS work
- Dissolving neighbouring parcels, districts or postcode areas into one outline.
- Merging overlapping buffers into a single catchment area before measuring it.
- Cleaning up a MultiPolygon whose parts overlap, which makes it invalid, into a valid one.
- Combining the parts of a feature that was digitised in pieces.
A worked example
The same two offset squares used on the ST_Intersection page:
A: POLYGON ((0 0, 6 0, 6 6, 0 6, 0 0))
B: POLYGON ((3 3, 9 3, 9 9, 3 9, 3 3))
ST_Union(A, B) = POLYGON ((6 3, 6 0, 0 0, 0 6, 3 6, 3 9, 9 9, 9 3, 6 3))
The result is one polygon of area 63: 36 plus 36, less the 9 they share, counted once. Dissolving the single input MULTIPOLYGON (((0 0, 6 0, 6 6, 0 6, 0 0)), ((3 3, 9 3, 9 9, 3 9, 3 3)), ((20 20, 21 20, 21 21, 20 21, 20 20))) gives a MultiPolygon of area 64: the overlapping pair merged, the far square kept as a separate part.
Using the ST_Union Geometry Tool
- Paste the first geometry, or a whole FeatureCollection to dissolve, into Geometry A, or select Load example.
- Optionally paste a second geometry into Geometry B; leave it empty to dissolve Geometry A on its own.
- Choose the output format and decimal places.
- Select Merge geometries, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Check the merged shape on the plot, then copy or download it.
When the output looks wrong
- Adjacent polygons merged into a MultiPolygon instead of one polygon
- Their shared edges do not line up exactly, so a sliver gap separates them. Snap the data to a common precision, or buffer each by a tiny amount before merging, to close gaps smaller than the data's accuracy.
- Thin slivers remain inside the merged polygon
- The inputs overlap or gap by tiny amounts, leaving narrow holes. They are real, as far as the coordinates are concerned; removing them needs a snapping or tolerance step that a union by itself does not apply.
- The union contains a GeometryCollection
- The inputs mixed points, lines and polygons that do not fall inside one another, so the result keeps each kind. A point inside a polygon is absorbed; one outside it has to stay a point.
Questions about the ST_Union Geometry Tool
How do I dissolve a whole FeatureCollection?
Paste it into Geometry A and leave Geometry B empty. Every feature is merged into one geometry, which is what SELECT ST_Union(geom) FROM table does in PostGIS.
Are attributes kept?
No. A union is about shape, and there is no rule for combining the properties of the features being merged. In a database you would group by an attribute and union each group.
Why is the merged area less than the sum of the inputs?
Overlapping parts are counted once. Two squares of 36 that overlap by 9 merge into 63, not 72.
Can it fix an invalid MultiPolygon?
If the only problem is that its parts overlap, dissolving it produces a valid geometry. Self-intersecting rings are a different problem that union refuses; the Geometry Validator explains how to fix those.
Is my data uploaded?
No. The union is computed in your browser.