Turf.jsCoordinate Mutation

turf.cleanCoords

What is turf.cleanCoords?

turf.cleanCoords removes redundant vertices from a GeoJSON geometry — duplicate consecutive coordinates, and colinear points that lie exactly on the line between their neighbours. It does not change the rendered shape; it just trims unnecessary vertices.

JavaScript
turf.cleanCoords(geojson, options?) → Feature<Geometry>

Options include:

  • mutateboolean (default false); when true, mutates the input in place instead of returning a new feature

When would you use turf.cleanCoords?

Use turf.cleanCoords as a pre-processing step before topology operations like turf.union, turf.intersect, or turf.simplify, where duplicate or colinear vertices can cause unexpected results or performance hits. It is also a good step before saving user-drawn geometry to your database.

In Node.js ETL, run cleanCoords on imported GeoJSON from inconsistent sources (Shapefile conversions, legacy WFS exports) to remove the extra vertices that tend to appear. For client-side draw tools on MapLibre, call it on the final shape before handing off to your backend.

Code
undefined

FAQs

Does it change the shape of my feature?

No. cleanCoords removes only exactly-colinear and exactly-duplicate vertices. The visible shape is unchanged. For shape-simplifying reduction, use turf.simplify instead.

Should I use mutate: true?

Only if you are confident no downstream code holds a reference to the original feature. Mutation saves memory on very large inputs but can cause subtle bugs in React or immutable-data codebases. In most web apps, leave it at false.

How do I install just cleanCoords?

npm install @turf/clean-coords. It depends on @turf/helpers and @turf/invariant.

Does it close open polygon rings?

Yes — polygons remain valid with their first coordinate equal to their last. cleanCoords respects this closure requirement and will not break it.