lineReduce
Description
Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
Name | Type | Description |
---|---|---|
geojson | Geometry | Feature<LineString | Polygon | MultiLineString | MultiPolygon> | object |
callback | Function | a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) |
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 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(...);