Find the nearest neighbour to a given origin

get_nearest_neighbour(origin, candidates)

Arguments

origin

A numeric vector of length two containing respectively the longitude and latitude coordinate of the origin location.

candidates

A data.frame or similar representing the set of possible neighbour locations to choose from. Should have only three columns, with the first column containing unique indices for each location, and the second and third column containing respectively the longitude and latitude coordinates of each location.

Value

A list of length two with element idx containing the index of the nearest neighbour and element dist containing the distance to it.

Note

Coordinates should be expressed in coordinate reference system EPSG:4326. The function assumes this to be true, and does not check for it.