distance_line {psyosphere}R Documentation

Add shortest distance to a line

Description

Add shortest distance to a line

Usage

distance_line(
  tracks, line, bind = TRUE, drop = TRUE, cname = "distances_to_line"
)

Arguments

tracks

psyo. Data frame with tracks.

line

list. A list with the column lon (numeric) and lat (numeric).

bind

logical. Return the distance as list (FALSE) or add it to tracks (TRUE).

drop

logical. If TRUE and only one observation is returned drop the data frame and collapse the return value to a vector.

cname

character. Column name of the returned calculation result.

Value

psyo or list. Distance in meter.

Credit

If you use Psyosphere for commercial use or research, please support us by include one off the following references:

Author(s)

Benjamin Ziepert. Please send feedback to: feedback-psyosphere@analyse-gps.com.

See Also

distance_peers, distance_point, distance_psyo

Examples

# Get data
data(psyo_rounds)
data(psyo_rounds_map)

# Set start and finish
lon <- c(6.849975, 6.849627, 6.850001, 6.850350, 6.849975)
lat <- c(52.241745, 52.241100, 52.241004, 52.241649, 52.241745)
polygon_start <- data.frame(lon, lat)
remove(lon, lat)

lon <- c(6.851810, 6.851000, 6.851489, 6.852296, 6.851810)
lat <- c(52.241800, 52.240300, 52.240163, 52.241657, 52.241794)
polygon_finish <- data.frame(lon, lat)
remove(lon, lat)

# Select between start and finish
psyo_rounds <- psyosphere::select_between_polygons(
  psyo_rounds, polygon_start, polygon_finish
)

# Finish line
finish <- data.frame(lon = c(6.851810,6.851000), lat = c(52.241800,52.240300))

# Plot tracks, selection polygons and finish line

plot <- psyosphere::plot_polygon(polygon_start, plot = psyo_rounds_map)
# plot <- psyosphere::plot_polygon(polygon_start)

plot <- psyosphere::plot_polygon(polygon_finish, plot = plot)
plot <- psyosphere::plot_tracks(psyo_rounds, t_id = "", plot = plot)
psyosphere::plot_line(finish, plot = plot)

# Add distance to line to dataframe
psyo_rounds <- psyosphere::distance_line(psyo_rounds,finish, TRUE)

[Package psyosphere version 0.1 Index]