Skip to main content
Version: 7.3.0

findSegment

描述

🌐 Description

使用 @turf/meta 索引从 GeoJSON 中查找特定的 2 顶点 LineString 片段。

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

允许使用负索引。Point 和 MultiPoint 将始终返回 null。

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

参数

🌐 Parameters

名称类型描述
geojsonFeatureCollection | Feature | Geometry任何 GeoJSON 要素或几何体
options?Object可选参数 (默认 {})
options.featureIndex?number功能索引 (默认 0)
options.multiFeatureIndex?number多特性索引 (默认 0)
options.geometryIndex?number几何索引 (默认 0)
options.segmentIndex?number段索引 (默认 0)
options.properties?Object将属性转换为输出 LineString (默认 {})
options.bbox?BBox将 BBox 转换为输出 LineString (默认 {})
options.id?number | string将 Id 转换为输出 LineString (默认 {})

返回

🌐 Returns

Feature<LineString> 2点 GeoJSON 特性线串

示例

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