Thursday 6 February 2020

postgis - Simplifying a multipolygon into one polygon respecting its outer boundaries


I have a multipolygon containing a one large polygon, itself containing a number of smaller polygons, which constitute 'holes' in the largest polygon.



My goal is to simplify the multipolygon into one polygon that closely respects the existing perimeter but removes all the smaller polygons (holes)


I have been using a combination of ST_ExteriorRing and ST_Dump to get rid of the points and lines, however I can't make this work when there are multiple polygons.


The closest working solution I've found is to use ST_ConcaveHull(geometry, 0.99), however this does not follow the perimeter of the shape closely enough (it smoothes over the recesses).


I've pasted the text representation of the multipolygon below https://gist.github.com/glennpjones/51acef849825470386f24a6c3259295d


I'm using PostGIS 2.5.


How would you approach this?



Answer



According to the data provided


Try to go that way:


SELECT ST_MakePolygon(ST_ExteriorRing((ST_Dump(geom)).geom)) geom FROM data ORDER BY geom ASC LIMIT 2;


It's gotta work...


or


WITH 
tbla AS (SELECT ST_MakePolygon(ST_ExteriorRing((ST_Dump(geom)).geom)) geom FROM data)
SELECT ST_Union(geom) geom FROM tbla;

If the system "swears" at the data, you can enhance it with the function ST_MakeValid...


Success in knowing...


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...