lineReduce
Description
Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
Name | Type | Description |
---|---|---|
geojson | FeatureCollection<Lines> | Feature<Lines> | Lines | Feature<GeometryCollection> | GeometryCollection | object |
callback | Function | a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) |
initialValue? | Reducer | Value to use as the first argument to the first call of the callback. |
Returns
Reducer The value that results from the reduction.
Examples
var multiPoly = turf.multiPolygon([
turf.polygon([
[
[12, 48],
[2, 41],
[24, 38],
[12, 48],
],
[
[9, 44],
[13, 41],
[13, 45],
[9, 44],
],
]),
turf.polygon([
[
[5, 5],
[0, 0],
[2, 2],
[4, 4],
[5, 5],
],
]),
]);
turf.lineReduce(
multiPoly,
function (
previousValue,
currentLine,
featureIndex,
multiFeatureIndex,
geometryIndex,
) {
//=previousValue
//=currentLine
//=featureIndex
//=multiFeatureIndex
//=geometryIndex
return currentLine;
},
);
Installation
$ npm install @turf/meta
import { lineReduce } from "@turf/meta";
const result = lineReduce(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.lineReduce(...);