Skip to main content
Version: 7.0.0

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

NameTypeDescription
geojsonFeatureCollection | Featureany GeoJSON object
callbackFunctiona method that takes (previousValue, currentProperties, featureIndex)
initialValue?*Value to use as the first argument to the first call of the callback.

Returns

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