Coordinate handling
Quick answer
This tutorial covers the cleanup helpers that regularize coordinates without changing shape: truncate and round for precision, cleanCoords for duplicate and collinear vertices, rewind for ring direction, flip for swapped axes, coordEach for custom passes, and destination with bearing for projecting points. You will be able to normalize messy imports before analysis.
Key points
- Use turf.truncate(feature, 6) for roughly 0.1-meter precision and turf.round for rounding instead.
- Remove duplicate vertices with turf.cleanCoords and enforce ring direction with turf.rewind.
- Compute new points with turf.destination(origin, distance, bearing, { units: 'kilometers' }).
Example
var raw = turf.point([116.39126345678, 39.90735912345], { id: 7 });
var cut = turf.truncate(raw, 6);
var rnd = turf.round(raw, 6);
console.log(turf.getCoord(cut)); // [116.391263, 39.907359]
console.log(turf.getCoord(rnd)); // [116.391263, 39.907359]
var cleaned = turf.truncate(turf.featureCollection([raw]), 6, { mutate: true });var messy = turf.lineString([
[116.391263, 39.907359],
[116.391263, 39.907359], // 重复
[116.400000, 39.907359], // 共线
[116.410000, 39.907359],
[116.410000, 39.920000]
]);
console.log('原始', messy.geometry.coordinates.length);
var clean = turf.cleanCoords(messy);
console.log('清理后', clean.geometry.coordinates.length);
Notes
- truncate clamps precision to six decimals, so passing 8 silently keeps fewer digits than expected.
- flip applied twice moves valid data to the wrong hemisphere while the map still draws a shape.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Coordinate handling. https://www.jingweizhi.com/en/turf/tutorials/coordinates.html (accessed 2026-11-03).