Skip to main content
Version: 7.0.0

featureReduce

Description

Reduce features in any GeoJSON object, similar to Array.reduce().

Parameters

NameTypeDescription
geojsonFeatureCollection | Feature | Geometryany GeoJSON object
callbackFunctiona method that takes (previousValue, currentFeature, 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.featureReduce(
features,
function (previousValue, currentFeature, featureIndex) {
//=previousValue
//=currentFeature
//=featureIndex
return currentFeature;
},
);

Installation

$ npm install @turf/meta

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

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