along
Quick answer
along walks a LineString from its start by a given distance and returns the point reached, following true arc length rather than interpolating endpoints. Call turf.along(line, distance, {units: 'kilometers'}); a distance beyond the total length clamps to the final vertex.
turf.along( line , distance , options ) → Feature<Point>
Key points
- Accepts a single LineString, not a MultiLineString or Polygon.
- units defaults to kilometers and also accepts miles, meters and degrees.
- Call turf.length first when you need the line's total distance.
Example
var route = turf.lineString([
[116.391263, 39.907359], // 天安门
[116.417600, 39.905200], // 崇文门
[116.455100, 39.909300] // 国贸方向
]);
/* 线长:公里 */
var total = turf.length(route, { units: 'kilometers' });
/* 每 500 米取一个点 */
var step = 0.5;
var marks = [];
for (var d = 0; d <= total; d += step) {
marks.push(turf.along(route, d, { units: 'kilometers' }));
}
console.log(total.toFixed(3), marks.length);var multi = turf.multiLineString([
[[116.39, 39.90], [116.42, 39.91]],
[[116.42, 39.91], [116.46, 39.93]]
]);
/* 多线先合并成单线再取点 */
var merged = turf.lineString(
multi.geometry.coordinates.reduce(function (acc, part) {
return acc.concat(part);
}, [])
);
var p = turf.along(merged, 1, { units: 'kilometers' });
Notes
- A negative distance walks backwards from the start vertex.
- MultiLineString input throws, so explode it into single lines first.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). along. https://www.jingweizhi.com/en/turf/api/along.html (accessed 2026-11-03).