I have approximately 1 million polygons that have been split by lines. However, this has caused one half of a polygon to be separated by approximately 50cm from its other half.

After doing a lot of attempts using a variety of methods I still have not come up with a reliable solution.

I would like to end up with individual features which have had the closest polygons merged together to create one feature. It probably needs to be based on a tolerance or buffer.

1) Using Union and SnapToGrid as explained by Paul Ramsey in another question (Joining lots of small polygons to form larger polygon using PostGIS?)

 SELECT ST_Union(ST_SnapToGrid(the_geom,0.0001)) 
 FROM parishes
 GROUP BY county_name;

This did a great job of doing a union on the parts of each polygon, however, I was left with just one feature. So my 1 million polygons and been merged into a MultiPart. Is there a way to stop this from happening?

2) Using Topology I then wondered if I might be able to use topology within PostGIS 2.0. I found this very difficult to implement as there are very few examples.

 -- Create a topology
SELECT CreateTopology('new_topology', 27700, 'geom'));

-- Add a layer
SELECT AddTopoGeometryColumn('new_topology', 'public', 'original_polygons', 'topogeom', 'MULTIPOLYGON');

This creates the edges and faces but how should I now use this to create a new polygon layer?

3) ST_Snap - it seems this will snap a geometry to another geometry. I could not get this to work as I was trying to snap to the same geometry. This may work though as I could snap the points on one side of the polygon to its matching set and then dissolve.

Are there any other options or advice on how to achieve what I am after?

  • 2
    Would it be too bad if you pass polygons by St_buffer(the_geom, 0.5), St_Union the result and the use again St_Buffer but with -0.5? The polygons should dissolve correctly but it's boundaries won't be exactly the same as before. Commented Jul 1, 2013 at 22:41

1 Answer 1


I think you should use ST_Dump to disaggregate your Multi-part polygon created in your step (1):

   FROM parishes
   GROUP BY county_name
  • 2
    I believe that the problem is that, due to the small gaps (50 cm) between polygons, the st_union is unable to dissolve the boundaries, and St_Dump will revert the problematic polygons back to it's initial state. Commented Jul 2, 2013 at 12:54
  • 2
    thanks Alexandre and mtn.biker, I tried both and the ST_Dump ends up doing what I needed, however I only got it working when i did this CREATE TABLE merged_dump AS SELECT (ST_Dump(ST_Union(ST_SnapToGrid(wkb_geometry,0.09)))).geom as geom FROM buildings;
    – tjmgis
    Commented Jul 3, 2013 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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