Skip to content

KBE3D / KBCore / turf / segmentEach

函数: segmentEach()

segmentEach<P>(geojson: AllGeoJSON, callback: (currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => void): void

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

类型参数

P

P extends GeoJsonProperties = GeoJsonProperties

参数

geojson

AllGeoJSON

any GeoJSON

callback

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

a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)

返回

void

示例

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

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

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

KBE3D @3.0.0 Copyright © 2024-present KBE3D