From dccbbe9486ce8f3134f212f9c1526d1df456f5e7 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Sat, 4 Apr 2020 19:42:03 +0100 Subject: [PATCH 1/3] Update for #486 --- 12-transport.Rmd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/12-transport.Rmd b/12-transport.Rmd index 30e9edde2..8b8877a01 100644 --- a/12-transport.Rmd +++ b/12-transport.Rmd @@ -355,7 +355,11 @@ desire_carshort = dplyr::filter(desire_lines, car_driver > 300 & distance < 5000 ``` ```{r 12-transport-18, eval=FALSE} -route_carshort = line2route(desire_carshort, route_fun = route_osrm) +route_carshort = route( + l = desire_carshort, + route_fun = osrm::osrmRoute, + point_input = TRUE + ) ``` `st_length()` determines the length of a linestring, and falls into the distance relations category (see also Section \@ref(distance-relations)). From 55225735e71a32da658b50659a867ff0f18c6e56 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Sat, 4 Apr 2020 22:35:35 +0100 Subject: [PATCH 2/3] Fix #486 --- 12-transport.Rmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/12-transport.Rmd b/12-transport.Rmd index 8b8877a01..296665c51 100644 --- a/12-transport.Rmd +++ b/12-transport.Rmd @@ -355,10 +355,11 @@ desire_carshort = dplyr::filter(desire_lines, car_driver > 300 & distance < 5000 ``` ```{r 12-transport-18, eval=FALSE} +library(osrm) route_carshort = route( l = desire_carshort, - route_fun = osrm::osrmRoute, - point_input = TRUE + route_fun = osrmRoute, + returnclass = "sf" # argument passed to route_fun ) ``` From 691654f1298bff22449fe96491082482ed1ee6d1 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Sun, 5 Apr 2020 22:28:28 +0100 Subject: [PATCH 3/3] Evaluate code for #486 --- 12-transport.Rmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/12-transport.Rmd b/12-transport.Rmd index 296665c51..c54df496a 100644 --- a/12-transport.Rmd +++ b/12-transport.Rmd @@ -14,6 +14,7 @@ library(dplyr) library(spDataLarge) library(stplanr) # geographic transport data package library(tmap) # visualization package (see Chapter 8) +library(osrm) # routing package ``` ## Introduction @@ -354,8 +355,7 @@ desire_lines$distance = as.numeric(st_length(desire_lines)) desire_carshort = dplyr::filter(desire_lines, car_driver > 300 & distance < 5000) ``` -```{r 12-transport-18, eval=FALSE} -library(osrm) +```{r 12-transport-18, message=FALSE} route_carshort = route( l = desire_carshort, route_fun = osrmRoute, @@ -546,11 +546,11 @@ To summarize, these were: identifying short but car-dependent commuting routes ( The final code chunk of this chapter combines these strands of analysis. It adds the car-dependent routes in `route_carshort` with a newly created object, `route_rail` and creates a new column representing the amount of travel along the centroid-to-centroid\index{centroid} desire lines they represent: -```{r 12-transport-25, eval=FALSE} -route_rail = desire_rail %>% +```{r 12-transport-25} +route_rail = desire_rail %>% st_set_geometry("leg_orig") %>% - line2route(route_fun = route_osrm) %>% - st_set_crs(4326) + route(l = ., route_fun = osrmRoute, returnclass = "sf") %>% + select(names(route_carshort)) ```