Atlaslog
Atlaslog / Turf.js / API / lineSlice
Turf.js · API reference

lineSlice

Quick answer

Takes a line, a start Point, and a stop point and returns a subsection of the line in-between those points. The start & stop points don't need to fall e.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Runnable examplesChinese noteAll API topics

Description​

Takes a line, a start Point, and a stop point and returns a subsection of the line in-between those points. The start & stop points don't need to fall exactly on the line.

This can be useful for extracting only the part of a route between waypoints.

Parameters​

NameTypeDescription
startPtCoordstarting point
stopPtCoordstopping point
lineFeature<LineString> | LineStringline to slice

Returns​

Feature<LineString> sliced line

Examples​

var line = turf.lineString([
[-77.031669, 38.878605],
[-77.029609, 38.881946],
[-77.020339, 38.884084],
[-77.025661, 38.885821],
[-77.021884, 38.889563],
[-77.019824, 38.892368],
]);
var start = turf.point([-77.029609, 38.881946]);
var stop = turf.point([-77.021884, 38.889563]);

var sliced = turf.lineSlice(start, stop, line);

Installation​

$ npm install @turf/line-slice

import { lineSlice } from "@turf/line-slice";
const result = lineSlice(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.lineSlice(...);
TutorialsAPI index
English reference text adapted from the official Turf.js documentation, © Turf.js contributors, licensed under MIT.
Original page: https://turfjs.org/docs/api/lineSlice · Chinese note: /turf/api/line-slice.html
Cite this page

Atlaslog (2026). lineSlice. https://www.jingweizhi.com/en/turf/api/line-slice.html (accessed 2026-11-03).