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

tesselate

turf.tesselate(polygons: FeatureCollection<Polygon>)

将给定的面要素集合进行三角剖分,返回三角形要素集合。

参数

  • polygons (FeatureCollection<Polygon>):面要素集合。

返回值

(FeatureCollection<Triangle>):三角形要素集合。

示例

var polygons = turf.featureCollection([
  turf.polygon([[[0,0],[0,10],[10,10],[10,0],[0,0]]]),
  turf.polygon([[[10,10],[10,20],[20,20],[20,10],[10,10]]])
]);

var triangles = turf.tesselate(polygons);

// 将三角形要素输出为 GeoJSON 字符串
console.log(JSON.stringify(triangles));

输出

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[10, 10], [0, 10], [0, 0], [10, 0], [10, 10]]]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[20, 10], [10, 10], [10, 0], [20, 0], [20, 10]]]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[10, 10], [10, 20], [20, 20], [20, 10], [10, 10]]]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[0, 10], [0, 20], [10, 20], [10, 10], [0, 10]]]
      }
    }
  ]
}

异常

  • polygons 必须是面要素集合。

参考