Skip to main content
Version: 6.5.0

lineSlice

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

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(...);