MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

segmentEach

描述

segmentEach 是一个 TURF 函数,用于将一个 Feature 对象或 FeatureCollection 对象的 LineString 类型的 Feature 进行线段切割。

用法

segmentEach(FeatureCollection|Feature, callback)
  • 参数:

    • FeatureCollection|Feature: 必填,表示要切割的 Feature 对象或 FeatureCollection 对象。
    • callback: 必填,表示每个线段的回调函数,函数的参数为线段的 Feature 对象。
  • 返回值:

    • 无返回值。

示例

var line = turf.lineString([[126,45],[123,48],[120,45],[117,48]]);
turf.segmentEach(line, function(segment) {
    console.log(segment);
});

输出结果:

{
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [[126,45],[123,48]]
    },
    "properties": {}
},
{
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [[123,48],[120,45]]
    },
    "properties": {}
},
{
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [[120,45],[117,48]]
    },
    "properties": {}
}

异常

  • 如果输入的不是 LineString 类型的 Feature,则会抛出异常 Error: input must be a LineString Feature or Geometry
  • 如果没有传入回调函数,则会抛出异常 Error: Missing callback