Is there a way to simplify multipolygon by removing small gaps in PostGIS? Example:
It could also simplify the shape as
ST_Simplify does but in addition it should remove small gaps between parts of the multipolygon.
In the upcoming PostGIS 3.3
ST_ConcaveHull has been enhanced so that it respects boundaries when polygons are provided as input. So for this case you should be able to simply create a concave hull around the input, with a suitable concaveness parameter.
See also this blog post on the Concave Hull of Polygons algorithm.
Join the layer to itself by distance, snap and union:
AS(select st_clusterdbscan(geom, 0, 2) over() cluster_id, geom
(select a.id as aid, case when a.geom is not null and b.geom is not null then st_snap(a.geom, b.geom, 500) else a.geom end as geom
from public.polywithgaps a
left join public.polywithgaps b
on st_dwithin(a.geom, b.geom, 500) --Change 500 to the distance you want to snap
and a.id<b.id) sub)
select st_union(geom) geom from clusters
where cluster_id is not null
group by cluster_id
select geom from clusters where cluster_id is null