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

lineIntersect

介绍

Turf的lineIntersect函数是用于计算两条线之间的交点的函数。它将返回两条线之间的交点坐标数组。

语法

turf.lineIntersect(line1, line2)

参数

  • line1 (Feature<LineString>): 第一条用于计算交点的线
  • line2 (Feature<LineString>): 第二条用于计算交点的线

返回值

  • results (FeatureCollection<Point>): 一个包含所有交点坐标的FeatureCollection对象。

示例

var line1 = turf.lineString([[0, 0], [10, 10]]);
var line2 = turf.lineString([[0, 10], [10, 0]]);
var intersects = turf.lineIntersect(line1, line2);

console.log(intersects);

输出:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          5,
          5
        ]
      },
      "properties": {}
    }
  ]
}

参考