nearestPoint
描述
¥Description
获取一个参考 point 和一个包含点几何特性的 FeatureCollection,并返回 FeatureCollection 中距离参考最近的点。此计算为测地线计算。
¥Takes a reference point and a FeatureCollection of Features with Point geometries and returns the point from the FeatureCollection closest to the reference. This calculation is geodesic.
参数
¥Parameters
名称 | 类型 | 描述 |
---|---|---|
targetPoint | 坐标系 | 参考点 |
points | FeatureCollection<点> | 针对输入点集 |
options? | 对象 | 可选参数(默认 {}) |
options.units? | string | 数值结果的单位(默认为 'kilometers') |
返回
¥Returns
¥Feature<Point> the closest point in the set to the reference point
示例
¥Examples
var targetPoint = turf.point([28.965797, 41.010086], {
"marker-color": "#0F0",
});
var points = turf.featureCollection([
turf.point([28.973865, 41.011122]),
turf.point([28.948459, 41.024204]),
turf.point([28.938674, 41.013324]),
]);
var nearest = turf.nearestPoint(targetPoint, points);
安装
¥Installation
$ npm install @turf/nearest-point
import { nearestPoint } from "@turf/nearest-point";
const result = nearestPoint(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.nearestPoint(...);