Skip to main content
Version: Next

coordReduce

Description

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

Parameters

NameTypeDescription
geojsonAllGeoJSONany GeoJSON object
callbackcoordReduceCallbacka method that takes (previousValue, currentCoord, coordIndex)
initialValue?ReducerValue 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

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