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? | 归约器 | 作为回调的第一次调用的第一个参数使用的值。 |
返回
🌐 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(...);