mt_interpolate: Linearly interpolate locations

View source: R/mt_interpolate.R

mt_interpolateR Documentation

Linearly interpolate locations

Description

Linear interpolation along the straight line between consecutive locations. Either interpolate to a time or intersection of a line.

Usage

mt_interpolate(x, time, max_time_lag, omit = FALSE, sf)

Arguments

x

A move2 object

time

The times to interpolate to, if missing the interpolation is to the empty locations. Alternatively if the timestamps in x are POSIXct then also an interval can be provided. For details on the interval specification see floor_date.

max_time_lag

The maximal time lag to interpolate over, if not provided any interval is interpolated

omit

If the original location that do not match a value in time should be omitted. This only takes affect when time is not missing.

sf

an sf or sfc collection of lines to interpolate to.

Details

Each interpolation is done along a straight path from the previous to the next location. Interpolation in time is done with st_line_sample when there is no CRS provided and s2_interpolate_normalized when the data has a projection.

Spatial interpolations will be useful, for example, to find out when a individual crosses a distance from its natal ground or leaves a territory. Furthermore it could be used to identify road crossings. In some cases it might useful to convert polygons to spatial lines using st_cast.

Value

A move2 object with the interpolated locations

Examples

data <- mt_sim_brownian_motion(t = c(0, 0.6, 3, 3.5))
## interpolating at specific times
mt_interpolate(data, c(.5, 1.5, 2.5))
line_sf <- sf::st_sf(data.frame(
  id = "test",
  geometry = sf::st_sfc(
    sf::st_linestring(cbind(
      c(-1, 1, 1, -1, -1),
      c(-1, -1, 1, 1, -1)
    ))
  )
))
mt_interpolate(data,
  sf = line_sf
)
## interpolating to empty locations
data$geometry[c(1, 3)] <- sf::st_point() ## creating empty locations
mt_interpolate(data)

fishers <- mt_read(mt_example())[1:200, ]
mt_interpolate(fishers, "2 hours")
## omit the original records
mt_interpolate(fishers, "2 hours", omit = TRUE)


move2 documentation built on March 13, 2026, 5:08 p.m.