描述
归约任何 GeoJSON 对象中的坐标,类似于 Array.reduce()
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | AllGeoJSON | 任何 GeoJSON 对象 |
| callback | coordReduceCallback | 接收 (previousValue, currentCoord, coordIndex) 的方法 |
| initialValue? | Reducer | 作为回调函数第一个参数首次调用的值。 |
| excludeWrapCoord? | boolean | 是否包含 LinearRing 的终点坐标(该坐标包裹环)。(默认 false) |
返回值
Reducer 归约结果值。
示例
javascript
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;
},
);安装
javascript
$ npm install @turf/meta
import { coordReduce } from "@turf/meta";
const result = coordReduce(...);javascript
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.coordReduce(...);