0

I am interested in learning how to work with Road Network Files in R.

For example, I would be interested in finding out the driving distance between the following two (Canadian) addresses:

  • CN Tower: 290 Bremner Blvd, Toronto, ON M5V 3L9
  • Toronto Airport: 6301 Silver Dart Dr, Mississauga, ON L5P 1B2

In the past, I would have used an API such as the OpenStreetMap (OSM):

   library(tmap)
    remotes::install_github("riatelab/osrm")
library(osrm)
    
    q1 = geocode_OSM("6301 Silver Dart Dr, Mississauga, ON L5P 1B2")
    q2 = geocode_OSM("290 Bremner Blvd, Toronto, ON M5V 3L9")
    
    q1 = as.numeric(q1$coords)
    q2 = as.numeric(q2$coords)
    
    q1_lat = q1[1]
    q1_long = q1[2]
    q2_lat = q2[1]
    q2_long = q2[2]
    
    route = osrmRoute(src = c(q1[1], q1[2]) ,  dst = c(q2[1], q2[2]), osrm.profile = "car")
    
    > route$distance
    [1] 26.2836

As we can see here, the driving distance between these two points is 26.2 KM (which is quite close to distance obtained from Google Maps)

I would now like to try and do something similar using a Road Network File.

For example, I found the following file which contains information about the Road Networks (https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/rnf-frr/index2021-eng.cfm?Year=21). I then downloaded this to my computer in .shp format (i.e. shapefile).

Based on such a file of Road Networks, is it possible to find out the "driving distance" between any two addresses (whether in "language address" or geographical coordinates)?

Note: This file appears to be quite large and I am not sure if my computer can fully load it - is it possible to command the computer to only import a smaller portion of this file? (e.g. import where province = ontario , import where city = toronto)

2
  • 1
    Hi! Please check luukvdmeer.github.io/sfnetworks and the vignettes included into the package
    – agila
    Mar 31, 2023 at 9:33
  • @ agila: thank you so much for your reply! If you have time, can you please show me how to use this for my question? Thank you so much!
    – stats_noob
    Mar 31, 2023 at 14:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.