描述
将任何 GeoJSON 对象中的属性归约为单个值,类似于 Array.reduce 的工作方式。但是,在这种情况下我们惰性运行归约,因此不需要所有属性的数组。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | FeatureCollection | Feature | Geometry | 任何 GeoJSON 对象 |
| callback | propReduceCallback | 接收 (previousValue, currentProperties, featureIndex) 的方法 |
| initialValue? | Reducer | 作为回调函数第一个参数首次调用的值。 |
返回值
Reducer 归约结果值。
示例
javascript
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;
},
);安装
javascript
$ npm install @turf/meta
import { propReduce } from "@turf/meta";
const result = propReduce(...);javascript
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.propReduce(...);