earthkit.geo.distance.nearest_point_kdtree

earthkit.geo.distance.nearest_point_kdtree(ref_points, points, figure=IFS_SPHERE)

Find the index of the nearest point to all ref_points in a set of points using a KDTree.

Parameters:
  • ref_points (pair of array-like) – Latitude and longitude coordinates of the reference point (degrees)

  • points (pair of array-like) – Locations of the set of points from which the nearest to ref_points is to be found. The first item specifies the latitudes, the second the longitudes (degrees)

  • figure (geo.figure.Figure, optional) – Figure of the spheroid the returned distances are computed on (default: geo.figure.IFS_SPHERE)

Returns:

  • ndarray – Indices of the nearest points to ref_points.

  • ndarray – The distance (m) between the ref_points and the corresponding nearest point in points. Computed on the surface of the spheroid defined by figure.

Examples

>>> from earthkit.geo import nearest_point_kdtree
>>> p_ref = (51.45, -0.97)
>>> p_lat = [44.49, 50.73, 50.1]
>>> p_lon = [11.34, 7.90, -8.1]
>>> nearest_point_kdtree(p_ref, (p_lat, p_lon))
(array([2]), array([523115.83147777]))
>>> from earthkit.geo import nearest_point_kdtree
>>> p_ref = [(51.45, 41.49, 12.29), (-0.97, 18.34, -17.1)]
>>> p_lat = [44.49, 50.73, 50.1]
>>> p_lon = [11.34, 7.90, -8.1]
>>> nearest_point_kdtree(p_ref, (p_lat, p_lon))
(array([2, 0, 2]), array([ 523115.83147777,  659558.55282001, 4283987.17429322]))