Skip to content

描述 ​

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

参数 ​

名称类型描述
geojsonFeatureCollection | Feature | GeometryObject | GeometryCollection | Feature<GeometryCollection>任何 GeoJSON 对象
callbackgeomReduceCallback接收 (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) 的方法
initialValue?Reducer作为回调函数第一个参数首次调用的值。

返回值 ​

Reducer 归约结果值。

示例 ​

javascript
var features = turf.featureCollection([
  turf.point([26, 37], { foo: "bar" }),
  turf.point([36, 53], { hello: "world" }),
]);

turf.geomReduce(
  features,
  function (
    previousValue,
    currentGeometry,
    featureIndex,
    featureProperties,
    featureBBox,
    featureId,
  ) {
    //=previousValue
    //=currentGeometry
    //=featureIndex
    //=featureProperties
    //=featureBBox
    //=featureId
    return currentGeometry;
  },
);

安装 ​

javascript
$ npm install @turf/meta

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

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