Skip to main content
Version: 7.2.0

coordReduce

描述

¥Description

减少任何 GeoJSON 对象中的坐标,类似于 Array.reduce()

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

参数

¥Parameters

名称类型描述
geojsonAllGeoJSON任意 GeoJSON 对象
callbackcoordReduceCallback一个方法,该方法接受 (previousValue, currentCoord, coordIndex)
initialValue?Reducer用作回调函数首次调用的第一个参数的值。
excludeWrapCoord?boolean是否在迭代中包含环绕环的 LinearRings 的最终坐标。(默认 false)

返回

¥Returns

Reducer 简化后的值。

¥Reducer The value that results from the reduction.

示例

¥Examples

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

turf.coordReduce(
features,
function (
previousValue,
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex,
) {
//=previousValue
//=currentCoord
//=coordIndex
//=featureIndex
//=multiFeatureIndex
//=geometryIndex
return currentCoord;
},
);

安装

¥Installation

$ npm install @turf/meta

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

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