# classification

# nearestPoint

npm install @turf/nearest-point

接收一组点要素集和一个参照物点要素,返回该点要素集里最接近参照物点的点要素,包括两个属性:在要素集里的 index、和参照物的距离(英里)

参数

入参 类型 描述
targetPoint Coord 参照物点要素
points FeatureCollection<Point> 点要素集

返回

Feature<Point>

范例

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);
/*
{
  type: "Feature",
  geometry: {
    type: "Point",
    coordinates: [28.973865, 41.011122]
  },
  properties: {
    featureIndex: 0,
    distanceToPoint: 0.6866892586431127
  }
}
*/
Last Updated: 7/30/2020, 10:58:36 AM