描述
归约任何 GeoJSON 对象中的要素,类似于 Array.reduce()。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | FeatureCollection<Lines> | Feature<Lines> | Lines | Feature<GeometryCollection> | GeometryCollection | 对象 |
| callback | Function | 接收 (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(...);