2

Reading the PostGIS manual, it appears both St_Union and ST_UnaryUnion should dissolve boundaries of overlapping polygons. However, a simple test shows the following:

Start data:

Test data

insert into test (name, geom) values
('Top Left', st_geomfromtext('POLYGON((0 1, 0 3, 2 3, 2 1, 0 1))', 4326)),
('Bottom Right', st_geomfromtext('POLYGON((1 0, 1 2, 3 2, 3 0, 1 0))', 4326));

ST_Union:

Union: one polygon

create table test_union as select
st_union(geom) as geom
from test;

ST_UnaryUnion

Unary Union: two polygons?

create table test_unary as select
st_unaryunion(geom) as geom
from test;

What explains this confusing behavior?

4

When you read http://postgis.net/docs/ST_UnaryUnion.html you should notice that function accepts one geometry geometry ST_UnaryUnion(geometry geom); Your query returns two rows, each one being a union on a single polygon. Try this instead:

SELECT ST_AsText(
ST_UnaryUnion(
ST_Collect(
st_geomfromtext('POLYGON((0 1, 0 3, 2 3, 2 1, 0 1))', 4326),
st_geomfromtext('POLYGON((1 0, 1 2, 3 2, 3 0, 1 0))', 4326))));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.