Is there a way to simplify multipolygon by removing small gaps in PostGIS? Example:
Original:
Simplified:
It could also simplify the shape as ST_Simplify
does but in addition it should remove small gaps between parts of the multipolygon.
Is there a way to simplify multipolygon by removing small gaps in PostGIS? Example:
Original:
Simplified:
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.
The result should look something like this:
See also this blog post on the Concave Hull of Polygons algorithm.
ERROR: lwgeom_concavehull: GEOS Error: IllegalStateException: Unable to find a convex corner
.
Commented
Aug 28, 2022 at 8:48
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
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.
Fun original geospatial solutions...