Skip to content

描述 ​

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

参数 ​

名称类型描述
geojsonFeatureCollection<Lines> | Feature<Lines> | Lines | Feature<GeometryCollection> | GeometryCollection对象
callbackFunction接收 (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) 的方法
initialValue?Reducer作为回调函数第一个参数首次调用的值。

返回值 ​

Reducer 归约结果值。

示例 ​

javascript
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;
  },
);

安装 ​

javascript
$ npm install @turf/meta

import { lineReduce } from "@turf/meta";
const result = lineReduce(...);
javascript
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.lineReduce(...);