Skip to main content
Version: 7.2.0

lineReduce

描述

¥Description

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

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

参数

¥Parameters

名称类型描述
geojsonFeatureCollection<行数> | 特性<行数> | 行数 | 特性<GeometryCollection> | GeometryCollectionobject
callback函数一个方法,该方法接受 (previousValue, currentLine, featureIndex, multiFeatureIndex, geomationIndex)
initialValue?Reducer用作回调函数首次调用的第一个参数的值。

返回

¥Returns

Reducer 简化后的值。

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