segmentReduce
描述
🌐 Description
在任何 GeoJSON 对象中减少 2-顶点线段,类似于 Array.reduce()。(多)点几何不包含线段,因此在此操作中会被忽略。
🌐 Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
参数
🌐 Parameters
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | FeatureCollection | Feature | Geometry | 任何 GeoJSON |
| callback | segmentReduceCallback | 一个方法,接收 (previousValue, currentSegment, currentIndex) |
| initialValue? | Reducer | 用作第一次调用回调时第一个参数的值 |
返回
🌐 Returns
归约器
示例
🌐 Examples
var polygon = turf.polygon([
[
[-50, 5],
[-40, -10],
[-50, -10],
[-40, 5],
[-50, 5],
],
]);
// Iterate over GeoJSON by 2-vertex segments
turf.segmentReduce(
polygon,
function (
previousSegment,
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex,
) {
//= previousSegment
//= currentSegment
//= featureIndex
//= multiFeatureIndex
//= geometryIndex
//= segmentIndex
return currentSegment;
},
);
// Calculate the total number of segments
var initialValue = 0;
var total = turf.segmentReduce(
polygon,
function (previousValue) {
previousValue++;
return previousValue;
},
initialValue,
);
安装
🌐 Installation
$ npm install @turf/meta
import { segmentReduce } from "@turf/meta";
const result = segmentReduce(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.segmentReduce(...);