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.

  • Please take the Tour, which explains how our "Focused question / Best answer" model operates. Questions about "best" methods fare poorly here. Polygon generalization is a large and complex topic without the difficulty introduced by multipart archipelagos. – Vince May 17 '18 at 10:27
  • what are your tools? GDAL/OGR obviously, QGIS? PostGIS? there's e.g. the old buffer-in/buffer-out trick or ST_ConvexHull via sqlite SQL in ogr2ogr (you can also dump your Mulits) – ThingumaBob May 17 '18 at 10:36
  • Vincen thanks, in your comment you are assuming that people making questions knows the complete jargon and have an average level of knowledge in the specific domain. In StackOverflow I have help people just "assimilating" what they wanted to know, even when language barriers, without having a dump of their mind in the correct encoding, are we computers or humans?. Robin took the time to make the point and explain the answer, which makes him a real contributor, not a moderating machine. – panchicore May 17 '18 at 11:58
  • If just for searching, a simple bounding box should do the trick – Matt May 17 '18 at 14:36

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.