Skip to main content
Version: 7.3.0

lineReduce

描述

🌐 Description

减少任何 GeoJSON 对象中的要素,类似于 Array.reduce()。

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

参数

🌐 Parameters

名称类型描述
geojsonFeatureCollection<Lines> | Feature<Lines> | Lines | Feature<GeometryCollection> | GeometryCollectionobject
callback函数一个接收 (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) 的方法
initialValue?归约器作为回调的第一次调用的第一个参数使用的值。

返回

🌐 Returns

归约器 归约操作的结果值。

示例

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