This function calculates the distance between sequential mouse clicks on a plotted map, by combining locator with a distance calculator, such as pointDistance.

dist_btw_clicks(
  calc_distance = raster::pointDistance,
  ...,
  add_paths = list(length = 0.025)
)

Arguments

calc_distance

A function that calculates distances between two sets of points, such as pointDistance. The first two arguments of this function must accept a dataframe comprising the x and y coordinates of the first and second set of points respectively. The function must return a numeric vector of distances between these.

...

Additional arguments passed to calc_distance, such as lonlat for pointDistance.

add_paths

(optional) A named list of arguments, passed to add_sp_path, to customise the paths added to the plot. add_paths = NULL suppresses this option.

Value

The function returns a dataframe with an integer ID for each path segment (`segment'), the first and second x and y coordinates (`x', `x2', `y', `y2`) and the distances between these points (`dist'). If add_paths is not NULL, the segments are drawn on the map.

Author

Edward Lavender

Examples

if (FALSE) {
raster::plot(dat_gebco)
dist_btw_clicks(lonlat = FALSE)
}