[postgis-users] Merging two overlapping polygons

Kevin Neufeld kneufeld at refractions.net
Thu Oct 1 08:18:37 PDT 2009


If I understand correctly, why don't you just ST_Union as you are doing below, then wrap the results in ST_Dump to 
explode the MULTI result.  Then you'll have your merged polygon where they overlap as well as any individual lone-ranger 
polygons.

SELECT (ST_Dump(singlegeom)).geom
FROM (
   SELECT ST_Multi(ST_Union(f.the_geom)) as singlegeom
   FROM mytable
) AS foo;

-- Kevin

Alexandre Dube wrote:
> Thanks for the help.
> 
> OK, using ST_Intersects should be fine when using only 2 geometries, but 
> how can I use this in a query on a table containing more than 15000 rows ?
> 
> ST_Union worked and returned a single multipolygon, that's a good 
> start.  Is it possible to merge "intersecting" polygons only in a 
> statement ?
> 
> So far :
> 
> SELECT mycolumn, ST_Multi(ST_Union(f.the_geom)) as singlegeom FROM 
> mytable As f GROUP BY mycolumn;
> 
> (btw, mycolumn has the same value for every row, i.e. is null)
> 
> Thanks a lot,
> 



More information about the postgis-users mailing list