Search code examples
node.jsgeojsongoogle-cloud-sql

How to simplify and remove overlap in GeoJSON polygons


I'm consuming an API that specifies areas using GeoJSON polygons (that I do not control) and using them to query data in a Cloud SQL database. The problem arises when many of the polygons have small artefacts that overlap, and Cloud SQL does not support this.

I would love some help on how to simplify or smoothen these polygons to remove these artefacts. I definitively do not need the level of detail specified in this polygon for my use case. In the example below I assume about 20-30 points would have been accurate enough.

Some ideas that come to mind is to snap coordinates to a grid and remove coordinates that overlap or to have lots of predefined regions and use this polygon to select what regions should be included, but I'm a noob in this field and expect there to be some good algorithms or solutions to this problem already.

Example GeoJSON: https://gist.github.com/kennethlynne/2c94a6b895fe3bac686b397df4405344 example

Problem area with overlap that I especially want to patch: example zoomed in


Solution

  • Take a look at the simplify method in the Turf.js library and see If that is the kind of simplification you are looking for:

    https://turfjs.org/docs/api/simplify

    Basically it's going to return a simplified GeoJSON polygon based on the tolerance you pass in the options parameter

    enter image description here