13 Finding Distance into a Common Route

To provide for an exact comparison of times based on distance into stage, we can map distances onto the “official” route.

However, if the official route does not match the actual route, we may get a “false” distance measures. For example, if the “official” route starts some way along the actual route as recorded in telemetry, then we will lose information at the start of the route.

Another approach might be to generate out own unofficial official route by creating a small buffer around the intersection of the captured route telemetry and then looking up roads using OSM within that buffered area; such a road should be unique (assuming that the stage route follows tracks that appear on OpenStreetMap) and could then be used as the official route.

dist_into_route = function(trj_utm, stage_route_utm) {
   # telem_df_full_utm =  st_transform(telem_df_full,
  #                         crs = st_crs(utm_proj4_string))
  full_pois_utm = st_sfc(st_multipoint(st_coordinates(trj_utm)),
                      crs=st_crs(trj_utm))
  full_pois_points_utm = st_cast(x = full_pois_utm, to = "POINT")
  full_pois_points_utm_sp = as(full_pois_points_utm, 'Spatial')
  
  # Find the distance along the route of the point on the route
  # nearest to each telemetry sample
  rgeos::gProject(as(stage_route_utm,"Spatial"),
                  full_pois_points_utm_sp,  normalized = FALSE)
}

We can now get the distance into route for each telemetry point:

# This throws a warning?
trj_evans$dist_into_route = dist_into_route(trj_evans, stage_route_utm)
trj_ogier$dist_into_route = dist_into_route(trj_ogier, stage_route_utm)

Another approach would be simple to project one driver’s route onto the route taken by a driver we are comparing them against and then finding times based distance into this common route projection.