propReduce
Description
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
Name | Type | Description |
---|---|---|
geojson | FeatureCollection | Feature | Geometry | any GeoJSON object |
callback | propReduceCallback | a method that takes (previousValue, currentProperties, featureIndex) |
initialValue? | Reducer | Value 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.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(...);