[GIS] How to clean/fix polygons in a Node.js application

geojsonmongodbnode-jsturf

I am working on a simple Node.js application where users can walk around an area with a mobile device using GPS. This track is stored as a Polygon, but sometimes (due to inaccurate GPS signals or users not walking strictly around something) the Polygon is invalid GeoJSON.

I am looking for a way to integrate cleanup/fixing functionality for my user-generated Polygons in my Node.js application that uses a MongoDB (Turf being my main tool for working with GeoJSON).

I have briefly looked at ST_MakeValid and prepair which both seem to do what I need, but I don't see an easy way to integrate either into my stack.

The question is whether there are any libraries that are either written in JavaScript or can easily be wrapped to be used via an npm and play nicely with my existing stack and doesn't require bringing in heavy-weights like PostGIS.

Best Answer

Although I am not cleaning up Polygons I have found a better approach. As users gather data for the polygon I think it may be better to simply collect all points and then use turf.concave to draw a Polygon. Technically it is not 100% accurate but given the jumpy GPS signals the solution is good enough for me.

Related Question