segmentEach
描述
🌐 Description
遍历任何 GeoJSON 对象中的 2 顶点线段,类似于 Array.forEach()。 (多)点几何不包含线段,因此在此操作中会被忽略。
🌐 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.
参数
🌐 Parameters
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | AllGeoJSON | 任何 GeoJSON |
| callback | segmentEachCallback | 一个接收 (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) 的方法 |
返回
🌐 Returns
void
示例
🌐 Examples
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++;
});
安装
🌐 Installation
$ npm install @turf/meta
import { segmentEach } from "@turf/meta";
const result = segmentEach(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.segmentEach(...);