[GIS] Simplify geometry

geojsonsimplify

Which is the best way to convert a complex multipolygon into simple and "merged" polygon?

For example, the red stroked polygon (drawn by hand of course) is the simplified version of the white multipolygon one:

enter image description here

The aim is to get rid of the little polygons by generalizing the zone, also, there is a multipolygon that could be converted into 2 simplified polygons features or a simplified multipolygon feature:

enter image description here

The purpose of doing this is to find a way to optimize an elasticsearch geo_shape index for searching geofenced queries. In this case, low resolution works to test the search capabilities.

link to the geojson gist. Original Norway shape was extracted from a kml and already simplified with ogr2ogr -simplify 0.125.

Best Answer

I see multiples ways to answer this complex problem, but do remember this is a complex and not really closed topic, like Vince said. First, if you want to test, you should probably import your data in Postgis to quickly test and see the result, then look for other tools/library if you want to industrialyze (or just read or export from Postgis), that's usually what I do.

The 2 simplest ways that I see right now are:

  • ST_ConcaveHull : it should do the trick, but it's often a little difficult to find the best parameter, but it should be the cleanest.
  • An algorithme called dilatation-erosion: you do a positive buffer, you union your geometry, and do a negative buffer after. The difficulty is also to find the good size for the buffer but it's more trivial to understand the effect of this parameter. For example in Postgis: ST_Buffer(ST_Union(ST_Buffer(geom, 1000)), -1000). Depending of the size of the buffer, you could still have multiple parts in your geometry. Maybe you should adjust this parameter depending of the largest distance between your polygons.

The resulting polygon should ensure you to not leave any part of your initial polygons appart. You can use a ST_Simplify after if you want to be sure to have a small number of points in your polygon.

Related Question