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
必须是面要素集合。