3 Using Official Route Data

To make most effective use of the telemetry data, we want to be able to identify the stage section data as well as the road section data. We can use the official stage route to filter data points from a set of location data that includes road section locations to just those points that lay along a route.

# Path to the route telemetry data
path = "../../wrcplus/notebooks/2021_secto_Rally_Finland"

geojson_filename = "data/finland_2021.geojson"

For more information on analysing rally stage routes, see Visualising WRC Rally Stages With rayshader and R.

3.1 Loading Official Stage Route Data

Let’s load in some route data:

geojson_sf = sf::st_read(geojson_filename)
## Reading layer `finland_2021' from data source 
##   `/Users/tonyhirst/Documents/GitHub/visualising-wrc-telemetry-data/src/data/finland_2021.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 13 features and 2 fields
## Geometry type: GEOMETRY
## Dimension:     XYZ
## Bounding box:  xmin: 24.86575 ymin: 61.52393 xmax: 26.20794 ymax: 62.39946
## z_range:       zmin: 0 zmax: 148.839
## Geodetic CRS:  WGS 84

Let’s also clean the data a little by removing the reference to the Z dimension, making a note of original co-ordinate reference scheme, and generating references to the route in both latlong and UTM forms:

stage_route  = geojson_sf[7,]  %>% st_zm()

# Grab a copy of the original projection
original_crs = st_crs(stage_route)

# Find the UTM zone for a sample a point on the route
crs_zone = lonlat2UTMzone(c(st_coordinates(stage_route)[1,1],

# Create the projection string
utm_proj4_string = st_crs(crs_zone)$proj4string
#"+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs"
# units in meters e.g. https://epsg.io/32632

# Transform the route projection
stage_route_utm = st_transform(stage_route,
                               crs = st_crs(utm_proj4_string))

3.2 Comparing Stage Route Telemetry and the Stage Route

Let’s plot the telemetry data on a map, and then compare it to the stage route data:

leaflet() %>% 
  addProviderTiles("OpenTopoMap", group = "OSM") %>% 
  addPolylines(data=tmp_route, color = "red", weight = 5) %>%
  addPolylines(data=stage_route, color = "black", weight = 3)

If you look closely at the map, you will see that the stage route trace (in black) closely follows the road indicated on the map, but the lower resolution route telemetry data (the red line) only falls at occasional points along it; a straight line connects the sample points.