描述
使用 @turf/meta 索引从 GeoJSON 中查找特定的 2 顶点 LineString 线段。
允许负索引。 Point 和 MultiPoint 始终返回 null。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | FeatureCollection | Feature | Geometry | 任何 GeoJSON Feature 或 Geometry |
| options? | Object | 可选参数 (默认 {}) |
| options.featureIndex? | number | Feature 索引 (默认 0) |
| options.multiFeatureIndex? | number | Multi-Feature 索引 (默认 0) |
| options.geometryIndex? | number | Geometry 索引 (默认 0) |
| options.segmentIndex? | number | Segment 索引 (默认 0) |
| options.properties? | Object | 将属性转换到输出 LineString (默认 {}) |
| options.bbox? | BBox | 将 BBox 转换到输出 LineString (默认 {}) |
| options.id? | number | string | 将 Id 转换到输出 LineString (默认 {}) |
返回值
Feature<LineString> 2 顶点 GeoJSON Feature LineString
示例
javascript
var multiLine = turf.multiLineString([
[
[10, 10],
[50, 30],
[30, 40],
],
[
[-10, -10],
[-50, -30],
[-30, -40],
],
]);
// 第一个线段(默认值为 0)
turf.findSegment(multiLine);
// => Feature<LineString<[[10, 10], [50, 30]]>>
// 第二个 Multi Feature 的第一个线段
turf.findSegment(multiLine, { multiFeatureIndex: 1 });
// => Feature<LineString<[[-10, -10], [-50, -30]]>>
// 最后一个 Multi Feature 的最后一个线段
turf.findSegment(multiLine, { multiFeatureIndex: -1, segmentIndex: -1 });
// => Feature<LineString<[[-50, -30], [-30, -40]]>>安装
javascript
$ npm install @turf/meta
import { findSegment } from "@turf/meta";
const result = findSegment(...);javascript
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.findSegment(...);