Atlaslog
Atlaslog / Turf.js / Tutorial / Coordinate handling
Turf.js · Tutorial

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.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Key points
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
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Coordinate handling. https://www.jingweizhi.com/en/turf/tutorials/coordinates.html (accessed 2026-11-03).