turf.lineOffset
What is turf.lineOffset?
turf.lineOffset returns a new LineString (or MultiLineString) offset perpendicular to the original by a given distance. Positive distances offset to the right of the direction of travel; negative distances to the left.
turf.lineOffset(line, distance, options?) → Feature<LineString | MultiLineString>Options include:
units—'kilometers'(default),'meters','miles','nauticalmiles','radians','degrees'
When would you use turf.lineOffset?
Use turf.lineOffset for drawing parallel lines — for example, rendering bidirectional traffic as two offset lines on a MapLibre map, creating bike-lane setbacks from road centrelines, or visualising corridor boundaries on either side of a route.
In Node.js it is useful for generating navigational buffers, offset annotations along a trail, or "ghost" versions of a route at a fixed lateral distance for planning workflows.
undefinedFAQs
How does it handle sharp corners?
The algorithm projects offset positions on each segment and joins them — sharp corners can produce self-intersections at tight angles. For critical-accuracy applications run turf.cleanCoords or manual validation after offsetting.
How do I install just lineOffset?
npm install @turf/line-offset. It depends on @turf/helpers and @turf/invariant.
Is the offset measured on the ground?
Yes — the distance is computed using geodetic math on the WGS84 sphere, so 5 meters offsets by approximately 5 metres on the ground at any latitude.
Does it work on MultiLineString?
Yes. Each part is offset independently. If you want the parts joined, merge them first with a helper or post-process the output.