Skip to main content
Version: 7.4.0

flattenReduce

Description​

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

Parameters​

NameTypeDescription
geojsonFeatureCollection | Feature | GeometryObject | GeometryCollection | Feature<GeometryCollection>any GeoJSON object
callbackflattenReduceCallbacka method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
initialValue?ReducerValue 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.multiPoint(
[
[40, 30],
[36, 53],
],
{ hello: "world" },
),
]);

turf.flattenReduce(
features,
function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
//=previousValue
//=currentFeature
//=featureIndex
//=multiFeatureIndex
return currentFeature;
},
);

Installation​

$ npm install @turf/meta

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

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