4

Is there a way to simplify multipolygon by removing small gaps in PostGIS? Example:

Original:

enter image description here

Simplified:

enter image description here

It could also simplify the shape as ST_Simplify does but in addition it should remove small gaps between parts of the multipolygon.

Martin Ždila
  • 572
  • 3
  • 11

3 Answers3

7

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.

The result should look something like this: enter image description here

See also this blog post on the Concave Hull of Polygons algorithm.

dr_jts
  • 5,038
  • 18
  • 15
7

Join the layer to itself by distance, snap and union:

WITH clusters 
  AS(select st_clusterdbscan(geom, 0, 2) over() cluster_id, geom 
  from 
    (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 union select geom from clusters where cluster_id is null

enter image description here

BERA
  • 72,339
  • 13
  • 72
  • 161
1

How about customizable buffering.

Configure and run this SQL script:

SELECT ST_Buffer((ST_Dump((ST_Union(ST_Buffer((geom),0.1, 'side=left join=mitre'))))).geom,-0.1,'side=left join=mitre') geom FROM <sourse_table>

You should get a result like in my image.

enter image description here

Fun original geospatial solutions...

Cyril Mikhalchenko
  • 4,397
  • 7
  • 14
  • 45