I have a big MultiPolygon layer in which I want to delete holes smaller than 100m².
QGIS do it well and fast with the algorithm "native:deleteholes"
, but I need to use it as part of a SQL workflow with PostGIS. I found this:
SELECT gid, ST_Collect(ST_MakePolygon(geom)) As geom
FROM (
SELECT gid, ST_ExteriorRing((ST_Dump(geom)).geom) As geom
FROM my_spatial_table
) s
GROUP BY gid;
But it does not allow to specify the max dimension of the holes to delete.
Is there a way?
Best Answer
This is one of those processes which are simple in an iterative language, but trickier in set-oriented SQL. But the
ST_DumpX
set-returning functions in PostGIS and the array handling in Postgres make it easier (but still fiddly to get working). The following solution works on MultiPolygons and also Polygons if they happen to be in the dataset.