Skip to main content
Version: 7.3.0

featureReduce

描述

🌐 Description

减少任何 GeoJSON 对象中的要素,类似于 Array.reduce()。

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

参数

🌐 Parameters

名称类型描述
geojsonFeatureCollection | Feature | Feature<GeometryCollection>任何 GeoJSON 对象
callbackfeatureReduceCallback一种接受(previousValue, currentFeature, featureIndex)的方法
initialValue?归约器作为回调的第一次调用的第一个参数使用的值。

返回

🌐 Returns

归约器 归约操作的结果值。

示例

🌐 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(...);