Skip to main content
Version: 7.2.0

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坐标系参考点
pointsFeatureCollection<>针对输入点集
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(...);