Skip to content

KBE3D / KBCore / turf / propReduce

函数: propReduce()

propReduce<Reducer, P>(geojson: Geometry | Feature<any, P> | FeatureCollection<any, P>, callback: (previousValue: Reducer, currentProperties: P, featureIndex: number) => Reducer, initialValue?: Reducer): Reducer

Function

Reduce properties in any GeoJSON object into a single value, similar to how Array.reduce works. However, in this case we lazily run the reduction, so an array of all properties is unnecessary.

类型参数

Reducer

Reducer

P

P extends GeoJsonProperties = GeoJsonProperties

参数

geojson

any GeoJSON object

Geometry | Feature<any, P> | FeatureCollection<any, P>

callback

(previousValue: Reducer, currentProperties: P, featureIndex: number) => Reducer

a method that takes (previousValue, currentProperties, featureIndex)

initialValue?

Reducer

Value to use as the first argument to the first call of the callback.

返回

Reducer

The value that results from the reduction.

示例

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

turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
  //=previousValue
  //=currentProperties
  //=featureIndex
  return currentProperties
});

KBE3D @3.0.0 Copyright © 2024-present KBE3D