Skip to main content
Version: 7.3.0

nearestPoint

描述

🌐 Description

以一个参考和一个包含点几何的要素集合(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

名称类型描述
targetPointCoord参考点
pointsFeatureCollection<Point>与输入点集相对
options?Object可选参数 (默认 {})
options.units?Units数值结果的单位。支持所有有效的 Turf Units(默认 'kilometers')

返回

🌐 Returns

Feature<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(...);