Skip to main content
Version: 7.2.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 | 特性 | 几何图形任意 GeoJSON 对象
callbackpropReduceCallback一个方法,该方法接受 (previousValue, currentProperties, featureIndex)
initialValue?Reducer用作回调函数首次调用的第一个参数的值。

返回

¥Returns

Reducer 简化后的值。

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