描述
返回点 集合 中离 线 最近的 point。返回的点具有 dist 属性,表示其到线的距离。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| points | FeatureCollection | GeometryCollection<Point> | 点集合 |
| line | Feature | Geometry<LineString> | 线要素 |
| options? | Object | 可选参数 (默认 {}) |
| options.units? | Units | 输出距离属性的单位。支持所有有效的 Turf Units。 (默认 'kilometers') |
| options.properties? | Object | 将属性转换到 Point (默认 {}) |
返回值
示例
javascript
var pt1 = turf.point([0, 0]);
var pt2 = turf.point([0.5, 0.5]);
var points = turf.featureCollection([pt1, pt2]);
var line = turf.lineString([
[1, 1],
[-1, 1],
]);
var nearest = turf.nearestPointToLine(points, line);安装
javascript
$ npm install @turf/nearest-point-to-line
import { nearestPointToLine } from "@turf/nearest-point-to-line";
const result = nearestPointToLine(...);javascript
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.nearestPointToLine(...);