Skip to main content
Version: Next

findSegment

Description

Finds a particular 2-vertex LineString Segment from a GeoJSON using @turf/meta indexes.

Negative indexes are permitted. Point & MultiPoint will always return null.

Parameters

NameTypeDescription
geojsonFeatureCollection | Feature | GeometryAny GeoJSON Feature or Geometry
options?ObjectOptional parameters (default {})
options.featureIndex?numberFeature Index (default 0)
options.multiFeatureIndex?numberMulti-Feature Index (default 0)
options.geometryIndex?numberGeometry Index (default 0)
options.segmentIndex?numberSegment Index (default 0)
options.properties?ObjectTranslate Properties to output LineString (default {})
options.bbox?BBoxTranslate BBox to output LineString (default {})
options.id?number | stringTranslate Id to output LineString (default {})

Returns

Examples

var multiLine = turf.multiLineString([
[
[10, 10],
[50, 30],
[30, 40],
],
[
[-10, -10],
[-50, -30],
[-30, -40],
],
]);

// First Segment (defaults are 0)
turf.findSegment(multiLine);
// => Feature<LineString<[[10, 10], [50, 30]]>>

// First Segment of 2nd Multi Feature
turf.findSegment(multiLine, { multiFeatureIndex: 1 });
// => Feature<LineString<[[-10, -10], [-50, -30]]>>

// Last Segment of Last Multi Feature
turf.findSegment(multiLine, { multiFeatureIndex: -1, segmentIndex: -1 });
// => Feature<LineString<[[-50, -30], [-30, -40]]>>

Installation

$ npm install @turf/meta

import { findSegment } from "@turf/meta";
const result = findSegment(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.findSegment(...);