data(flowlines) # load demo flowlines dataset
# Don't run as requires gdal dependency, can cause issues
library(rgdal)
flowlines <- spTransform(flowlines, CRS("+init=epsg:27700"))
flowlines <- flowlines[rgeos::gLength(flowlines, byid = TRUE) > 0,]
flowlines <- spTransform(flowlines, CRS("+init=epsg:4326"))
plot(flowlines)
cckey <- readLines("~/Dropbox/dotfiles/cyclestreets-api-key-rl")
Sys.setenv(CYCLESTREET = cckey)
routes_fast <- line2route(l = flowlines, plan = "fastest")
routes_slow <- line2route(l = flowlines, plan = "quietest", silent = TRUE)
flowlines <- flowlines[flowlines$Area.of.residence != flowlines$Area.of.workplace,]
# Save the route data (uncomment if this changes)
# devtools::use_data(routes_fast, overwrite = TRUE)
# devtools::use_data(routes_slow, overwrite = TRUE)
if(!exists("routes_fast")){
data(routes_fast, routes_slow) # load routes
}
plot(flowlines)
lines(routes_fast, col = "red")
lines(routes_slow, col = "green")
# Plot for a single line to compare 'fastest' and 'quietest' route
n = 18
plot(flowlines[n,])
lines(routes_fast[n,], col = "red")
lines(routes_slow[n,], col = "green")
Run the code above in your browser using DataLab