Skip to content

描述 ​

遍历任何 GeoJSON 对象中的 2 顶点线段,类似于 Array.forEach()。 (Multi)Point 几何体不包含线段,因此在操作期间被忽略。

参数 ​

名称类型描述
geojsonAllGeoJSON任何 GeoJSON
callbacksegmentEachCallback接收 (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) 的方法

返回值 ​

void

示例 ​

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

// 按 2 顶点线段遍历 GeoJSON
turf.segmentEach(
  polygon,
  function (
    currentSegment,
    featureIndex,
    multiFeatureIndex,
    geometryIndex,
    segmentIndex,
  ) {
    //=currentSegment
    //=featureIndex
    //=multiFeatureIndex
    //=geometryIndex
    //=segmentIndex
  },
);

// 计算线段总数
var total = 0;
turf.segmentEach(polygon, function () {
  total++;
});

安装 ​

javascript
$ npm install @turf/meta

import { segmentEach } from "@turf/meta";
const result = segmentEach(...);
javascript
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.segmentEach(...);