mt_distance {move2} | R Documentation |
Return distances or speeds between locations
Description
The distance or speed is calculated between consecutive locations
Usage
mt_distance(x, units)
mt_speed(x, units)
Arguments
x |
a |
units |
Optional. Valid values are |
Details
mt_is_time_ordered_non_empty_points
can be used to check if the timestamps are ordered and if the object only
contains location data. To omit empty locations use e.g. dplyr::filter(x,!sf::st_is_empty(x))
.
Distances are calculated using sf::st_distance.
Value
a vector of the same length as the move2
object containing the distances/speeds between locations.
Each element is the distance/speed to the next location.
The last value for each track will be NA
. Units are included when the data have a coordinate reference system set.
See Also
Other track-measures:
mt_azimuth()
,
mt_time()
Examples
## distance between consecutive locations
mt_sim_brownian_motion() |>
mt_distance() |>
head()
## When the data has a coordinate reference system set,
## units are included
dist <- mt_sim_brownian_motion(1:4) |>
sf::st_set_crs(4326L) |>
mt_distance()
dist
## transform units of output
units::set_units(dist, km)
## speed between consecutive locations
mt_sim_brownian_motion() |> mt_speed()
## When projections are provided units are included
data <- mt_read(mt_example())[330:340, ]
speed_calc <- data |>
mt_speed()
speed_calc
## transform units of output
units::set_units(speed_calc, m / s)
## Different projection gives same speed
data |>
sf::st_transform("+proj=aeqd +units=km +lon_0=-73.9 +lat_0=42.7") |>
mt_speed() |>
units::set_units(m / s)