turf.lineSliceAlong
What is turf.lineSliceAlong?
turf.lineSliceAlong returns the portion of a LineString between a starting distance and a stopping distance measured along the line from its first vertex.
turf.lineSliceAlong(line, startDist, stopDist, options?) → Feature<LineString>Options include:
units—'kilometers'(default),'meters','miles','nauticalmiles','radians','degrees'
When would you use turf.lineSliceAlong?
Use turf.lineSliceAlong when you reference positions by distance — animating progress along a route by slicing from 0 to the current distance each frame, extracting milepost-based stretches of a highway, or slicing a track based on elapsed time converted to distance.
In Node.js, it is a direct tool for linear referencing workflows where events are stored as "start at X km, end at Y km" and you want to materialise the geometry corresponding to that range.
undefinedFAQs
What if stopDist exceeds the line length?
The slice is clamped at the end of the line — you get the portion from startDist to the endpoint.
How do I install just lineSliceAlong?
npm install @turf/line-slice-along. It depends on @turf/helpers, @turf/invariant, and @turf/bearing.
Does the slice start and end snap to existing vertices?
No — new vertices are inserted at the exact slice positions, which may land between existing vertices. The result is a new LineString with clean endpoints.
How does this differ from turf.along?
turf.along returns a single point at a given distance. turf.lineSliceAlong returns the sub-line between two distances. Use along for markers; use lineSliceAlong for highlighted sections.