Skip to content

KBE3D / KBCore / turf / segmentReduce

函数: segmentReduce()

segmentReduce<Reducer, P>(geojson: GeometryCollection<Geometry> | Lines | FeatureCollection<Lines, P> | Feature<Lines, P> | Feature<GeometryCollection<Geometry>, P>, callback: (previousValue?: Reducer, currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => Reducer, initialValue?: Reducer): Reducer

Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.

类型参数

Reducer

Reducer

P

P extends GeoJsonProperties = GeoJsonProperties

参数

geojson

any GeoJSON

GeometryCollection<Geometry> | Lines | FeatureCollection<Lines, P> | Feature<Lines, P> | Feature<GeometryCollection<Geometry>, P>

callback

(previousValue?: Reducer, currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => Reducer

a method that takes (previousValue, currentSegment, currentIndex)

initialValue?

Reducer

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

返回

Reducer

示例

ts
var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);

// Iterate over GeoJSON by 2-vertex segments
turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
  //= previousSegment
  //= currentSegment
  //= featureIndex
  //= multiFeatureIndex
  //= geometryIndex
  //= segmentIndex
  return currentSegment
});

// Calculate the total number of segments
var initialValue = 0
var total = turf.segmentReduce(polygon, function (previousValue) {
    previousValue++;
    return previousValue;
}, initialValue);

KBE3D @3.0.0 Copyright © 2024-present KBE3D