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 move2 object. Timestamps must be ordered within tracks and only contain location data (See 'Details').

units

Optional. Valid values are character, symbolic_units or units, for more details see the value argument of units::as_units. If no units are stated (default) the function flexibly determines the units to return. Fixing the units can be useful if specific return units are for example required for subsequent functions. This argument only takes effect if the initial return value already has units.

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)


[Package move2 version 0.3.0 Index]