Monday, 9 December 2019

PostGIS Dissolve/Union close polygons


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?)


 CREATE TABLE merged AS
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?



Answer



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


SELECT ST_Dump( 

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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...