Skip to main content
Version: Next

featureReduce

描述

¥Description

Reduce features in any GeoJSON object, similar to Array.reduce().

参数

¥Parameters

名称类型描述
geojsonFeatureCollection | 特性 | 特性<GeometryCollection>任意 GeoJSON 对象
callbackfeatureReduceCallbacka method that takes (previousValue, currentFeature, featureIndex)
initialValue?ReducerValue to use as the first argument to the first call of the callback.

返回

¥Returns

Reducer The value that results from the reduction.

示例

¥Examples

var features = turf.featureCollection([
turf.point([26, 37], { foo: "bar" }),
turf.point([36, 53], { hello: "world" }),
]);

turf.featureReduce(
features,
function (previousValue, currentFeature, featureIndex) {
//=previousValue
//=currentFeature
//=featureIndex
return currentFeature;
},
);

安装

¥Installation

$ npm install @turf/meta

import { featureReduce } from "@turf/meta";
const result = featureReduce(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.featureReduce(...);