Skip to main content
Version: 7.3.0

propReduce

描述

🌐 Description

将任何 GeoJSON 对象中的属性归约为单个值,类似于 Array.reduce 的工作方式。然而,在这种情况下,我们是惰性运行归约,所以不需要所有属性的数组。

🌐 Reduce properties in any GeoJSON object into a single value, similar to how Array.reduce works. However, in this case we lazily run the reduction, so an array of all properties is unnecessary.

参数

🌐 Parameters

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

返回

🌐 Returns

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

示例

🌐 Examples

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

turf.propReduce(
features,
function (previousValue, currentProperties, featureIndex) {
//=previousValue
//=currentProperties
//=featureIndex
return currentProperties;
},
);

安装

🌐 Installation

$ npm install @turf/meta

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

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