Skip to main content
Version: 6.5.0

coordReduce

Description​

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

Parameters​

NameTypeDescription
geojsonFeatureCollection | Geometry | Featureany GeoJSON object
callbackFunctiona method that takes (previousValue, currentCoord, coordIndex)
initialValue?*Value to use as the first argument to the first call of the callback.
excludeWrapCoord?booleanwhether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (default false)

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.coordReduce(
features,
function (
previousValue,
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex,
) {
//=previousValue
//=currentCoord
//=coordIndex
//=featureIndex
//=multiFeatureIndex
//=geometryIndex
return currentCoord;
},
);

Installation​

$ npm install @turf/meta

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

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