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 | 特性 | 几何图形 | 任意 GeoJSON |
callback | segmentReduceCallback | 一个方法,该方法接受 (previousValue, currentSegment, currentIndex) |
initialValue? | Reducer | 用作回调函数首次调用的第一个参数的值。 |
返回
¥Returns
Reducer
示例
¥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(...);