Skip to main content
Version: 7.3.0

geomReduce

描述

🌐 Description

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

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

参数

🌐 Parameters

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

返回

🌐 Returns

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

示例

🌐 Examples

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

安装

🌐 Installation

$ npm install @turf/meta

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

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