This function handles missing GPS positions by rounding the timestamps to the nearest minute using a specified rounding function, and then merging the resulting timestamps with the ferrybox position data. It updates the missing latitude and longitude values based on the rounded timestamps.

handle_missing_positions(
  data,
  ferrybox_position,
  rounding_function,
  lat_col,
  lon_col
)

Arguments

data

A data frame containing timestamps and GPS positions.

ferrybox_position

A data frame containing timestamps and GPS positions from ferrybox.

rounding_function

A function used to round the timestamps. This can be `lubridate::floor_date`, `lubridate::ceiling_date`, or any other suitable rounding function.

lat_col

The name of the new latitude column to be created.

lon_col

The name of the new longitude column to be created.

Value

A data frame with updated GPS positions where the positions were missing. The returned data frame contains the original timestamps and the new columns for latitude and longitude based on the rounded timestamps.

Examples

# Example usage:
data <- data.frame(timestamp = Sys.time() + 1:10 * 60,
                   gpsLatitude = c(NA, runif(9)),
                   gpsLongitude = c(NA, runif(9)))
ferrybox_position <- data.frame(timestamp_minute = lubridate::round_date(Sys.time(),
                                                                         "minutes") + 1:10 * 60,
                                ferrybox_latitude = runif(10),
                                ferrybox_longitude = runif(10))
if(lubridate::second(Sys.time()) < 30) {
  updated_data <- iRfcb:::handle_missing_positions(data,
                                                   ferrybox_position,
                                                   lubridate::floor_date,
                                                   "gpsLatitude_floor",
                                                   "gpsLongitude_floor")
} else {
  updated_data <- iRfcb:::handle_missing_positions(data,
                                                   ferrybox_position,
                                                   lubridate::ceiling_date,
                                                   "gpsLatitude_ceiling",
                                                   "gpsLongitude_ceiling")
}