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.


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.


You may want to give Mapshaper a try. It allows you to snap vertices when you load a file. And if that doesn't fix everything, you can try repairing it once it's loaded.

You can also find a web-based UI for Mapshaper here.

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.