Skip to content

Commit 32d0166

Browse files
committed
tidy routing
1 parent c729ca2 commit 32d0166

1 file changed

Lines changed: 60 additions & 27 deletions

File tree

routing.qmd

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ engine: knitr
1111
::: callout-note
1212
### OD data
1313

14-
If you have **travel survey** data, for some exercises you may use that one. See also [Jittering](jittering.qmd), if needed.
14+
If you have **travel survey** data, for some exercises you may use that one.
15+
See also [Jittering](jittering.qmd), if needed.
1516

1617
For all the other, we can simply use **census** data.
1718
:::
@@ -26,11 +27,15 @@ nrow(POINTS) # 2822
2627
sum(POINTS$residents) # 545.796
2728
```
2829

29-
With census data, each statistical unit represents \~300 residents. In Lisbon, we have 2822 census units.
30+
With census data, each statistical unit represents \~300 residents.
31+
In Lisbon, we have 2822 census units.
3032

31-
Routing between all origins and destinations (2822 x 2822 = **7.963.684 OD pairs**) can potentially be a long-duration process. Nothing that r5r wouldn't handle! 🙂
33+
Routing between all origins and destinations (2822 x 2822 = **7.963.684 OD pairs**) can potentially be a long-duration process.
34+
Nothing that r5r wouldn't handle!
35+
🙂
3236

33-
But here we will consider a `city_center` location, and route our census population to the city center. Search in an online map the coordinates for a point that you would like to consider your attractor.
37+
But here we will consider a `city_center` location, and route our census population to the city center.
38+
Search in an online map the coordinates for a point that you would like to consider your attractor.
3439

3540
```{r}
3641
# Create origin point - Baixa / Downtown
@@ -86,7 +91,8 @@ hist(ttm_car$travel_time_p50)
8691

8792
By car, all the 2822 points with residents are able to be reach from city center.
8893

89-
In free-flow, the longest trip takes 26 minutes. 50% of the trips are shorter than 12 minutes.
94+
In free-flow, the longest trip takes 26 minutes.
95+
50% of the trips are shorter than 12 minutes.
9096

9197
### Walk
9298

@@ -124,29 +130,40 @@ hist(ttm_walk$travel_time_p50)
124130

125131
![](images/clipboard-2894920258.png){fig-align="center"}
126132

127-
The longest trip takes 120 minutes (equal to the max travel time). The time distribution is pretty even.
133+
The longest trip takes 120 minutes (equal to the max travel time).
134+
The time distribution is pretty even.
128135

129136
### Bike
130137

131138
When considering **bike** trips, we can also set a maximum level of traffic stress [@LTSmineta] that cyclists will tolerate.
132139

133140
#### LTS
134141

135-
A value of 1 means cyclists will only travel through the quietest streets, while a value of 4 indicates cyclists can travel through any road. **Defaults to 2, which can be very restrictive in Lisbon (depends on your case study).**
142+
A value of 1 means cyclists will only travel through the quietest streets, while a value of 4 indicates cyclists can travel through any road.
143+
**Defaults to 2, which can be very restrictive in Lisbon (depends on your case study).**
136144

137145
From @Pereira2021r5r:
138146

139-
When cycling is enabled in `R5` (by passing the value `BIKE` to either `mode` or `mode_egress`), setting `max_lts` will allow cycling only on streets with a given level of danger/stress. Setting `max_lts` to 1, for example, will allow cycling only on separated bicycle infrastructure or low-traffic streets and routing will revert to walking when traversing any links with LTS exceeding 1. Setting `max_lts` to 3 will allow cycling on links with LTS 1, 2 or 3. Routing also reverts to walking if the street segment is tagged as non-bikable in OSM (e.g. a staircase), independently of the specified max LTS.
147+
When cycling is enabled in `R5` (by passing the value `BIKE` to either `mode` or `mode_egress`), setting `max_lts` will allow cycling only on streets with a given level of danger/stress.
148+
Setting `max_lts` to 1, for example, will allow cycling only on separated bicycle infrastructure or low-traffic streets and routing will revert to walking when traversing any links with LTS exceeding 1.
149+
Setting `max_lts` to 3 will allow cycling on links with LTS 1, 2 or 3.
150+
Routing also reverts to walking if the street segment is tagged as non-bikable in OSM (e.g. a staircase), independently of the specified max LTS.
140151

141-
The default methodology for assigning LTS values to network edges is based on commonly tagged attributes of OSM ways. See more info about LTS in the original documentation of R5 from Conveyal at <https://docs.conveyal.com/learn-more/traffic-stress>. In summary:
152+
The default methodology for assigning LTS values to network edges is based on commonly tagged attributes of OSM ways.
153+
See more info about LTS in the original documentation of R5 from Conveyal at <https://docs.conveyal.com/learn-more/traffic-stress>.
154+
In summary:
142155

143-
- **LTS 1**: Tolerable for children. This includes low-speed, low-volume streets, as well as those with separated bicycle facilities (such as parking-protected lanes or cycle tracks).
156+
- **LTS 1**: Tolerable for children.
157+
This includes low-speed, low-volume streets, as well as those with separated bicycle facilities (such as parking-protected lanes or cycle tracks).
144158

145-
- **LTS 2**: Tolerable for the mainstream adult population. This includes streets where cyclists have dedicated lanes and only have to interact with traffic at formal crossing.
159+
- **LTS 2**: Tolerable for the mainstream adult population.
160+
This includes streets where cyclists have dedicated lanes and only have to interact with traffic at formal crossing.
146161

147-
- **LTS 3**: Tolerable for "enthused and confident" cyclists. This includes streets which may involve close proximity to moderate- or high-speed vehicular traffic.
162+
- **LTS 3**: Tolerable for "enthused and confident" cyclists.
163+
This includes streets which may involve close proximity to moderate- or high-speed vehicular traffic.
148164

149-
- **LTS 4**: Tolerable only for "strong and fearless" cyclists. This includes streets where cyclists are required to mix with moderate- to high-speed vehicular traffic.
165+
- **LTS 4**: Tolerable only for "strong and fearless" cyclists.
166+
This includes streets where cyclists are required to mix with moderate- to high-speed vehicular traffic.
150167

151168
For advanced users, you can provide custom LTS values by adding a tag `<key = "lts">` to the `osm.pbf` file.
152169

@@ -184,19 +201,23 @@ When estimating travel time with public transit, some considerations should be p
184201

185202
- **Date and time** of the trips
186203

187-
- Which **modes** are allowed? All or just some of PT?
204+
- Which **modes** are allowed?
205+
All or just some of PT?
188206

189207
- How many **transfers** are allowed
190208

191-
- How to **get to the PT stop**? By foot, bike or car? The same from the last stop to the destination
209+
- How to **get to the PT stop**?
210+
By foot, bike or car?
211+
The same from the last stop to the destination
192212

193213
- How many minutes it is **reasonable to walk** (of bike) in max during the whole trip?
194214

195215
- Is my best time-travel estimate the same, if I consider a 5min **time-window** period or a 30min time-window period?
196216

197217
#### Date and time
198218

199-
This is a very relevant parameter (`departure_datetime)`. If your selected date is not part of your GTFS calendar, you will not be able to estimate travel by **PT** on those dates.
219+
This is a very relevant parameter (`departure_datetime)`.
220+
If your selected date is not part of your GTFS calendar, you will not be able to estimate travel by **PT** on those dates.
200221

201222
##### Confirm service calendar
202223

@@ -219,7 +240,8 @@ uses stop_times (no frequencies)
219240
# shapes 307
220241
```
221242

222-
My GTFS runs from **2025-09-01** to **2025-12-01**. I will select a **working day**, and a **peak hour** for this exercises.
243+
My GTFS runs from **2025-09-01** to **2025-12-01**.
244+
I will select a **working day**, and a **peak hour** for this exercises.
223245

224246
```{r}
225247
departure_datetime = as.POSIXct("01-10-2025 08:00:00", # wednesday
@@ -230,7 +252,8 @@ When I change this parameter, my results may be totally different.
230252

231253
#### Modes
232254

233-
`R5` allows for multiple combinations of transport modes. The options include:
255+
`R5` allows for multiple combinations of transport modes.
256+
The options include:
234257

235258
- **Transit modes:** `TRAM`, `SUBWAY`, `RAIL`, `BUS`, `FERRY`, `CABLE_CAR`, `GONDOLA`, `FUNICULAR`.\
236259
The option `TRANSIT` automatically considers **all public transport modes** available.
@@ -239,13 +262,16 @@ When I change this parameter, my results may be totally different.
239262

240263
#### Transfers
241264

242-
The maximum number of public transport rides allowed in the same trip. The `max_rides` defaults to 3. Consider a plausible number, and take into consideration that shifting from one metro line to other will be considered as 2 rides.
265+
The maximum number of public transport rides allowed in the same trip.
266+
The `max_rides` defaults to 3.
267+
Consider a plausible number, and take into consideration that shifting from one metro line to other will be considered as 2 rides.
243268

244269
#### Egress mode and max walk time
245270

246271
The transport mode used after egress from the last public transport.\
247272
It can be either `WALK`, `BICYCLE` or `CAR`.\
248-
Defaults to `WALK`. Ignored when public transport is not used.
273+
Defaults to `WALK`.
274+
Ignored when public transport is not used.
249275

250276
The `max_walk_time` (or bike or car) time (in minutes) to access and egress the transit network, to make transfers within the network or to complete walk-only trips.
251277

@@ -257,7 +283,8 @@ To calculate the travel time from A to B, or to calculate the accessibility leve
257283

258284
Even a small difference, say leaving at `10:00am` or `10:04am` might importantly change travel time and accessibility estimates depending on when a person departs relative to when a public transport vehicle arrives, and how well transfers are coordinated given a service timetable.
259285

260-
When `time_window` is set, R^5^ computes multiple travel times / accessibility estimates starting at the specified `departure_datetime` and within the `time_window` selected by the user. By default, `r5r` will generate **one estimate per minute**.
286+
When `time_window` is set, R^5^ computes multiple travel times / accessibility estimates starting at the specified `departure_datetime` and within the `time_window` selected by the user.
287+
By default, `r5r` will generate **one estimate per minute**.
261288

262289
By default, r5r results have the **50th percentile** of travel time.
263290

@@ -303,7 +330,8 @@ summary(ttm_transit$travel_time_p50)
303330

304331
![](images/clipboard-2721979667.png)
305332

306-
50% of the trips take less than 31 minutes. The distribution is pretty normal.
333+
50% of the trips take less than 31 minutes.
334+
The distribution is pretty normal.
307335

308336
::: {.callout-tip appearance="simple"}
309337
Try to change some parameters, such as the `max_rides` or the `max_trip_duration` and compare the results.
@@ -313,13 +341,15 @@ Try to change some parameters, such as the `max_rides` or the `max_trip_duration
313341

314342
With the [`detailed_itineraries`](https://ipeagit.github.io/r5r/reference/detailed_itineraries.html)`()`, we can extract more information about each trip, such as:
315343

316-
- Which modes were used for trip *x*? In which order?
344+
- Which modes were used for trip *x*?
345+
In which order?
317346

318347
- What is the duration for each leg?
319348

320349
- Which route (shape) was estimated?
321350

322-
This function is also pretty flexible and allows to see more details. Also, because of this, it may require some **more processing cost**.
351+
This function is also pretty flexible and allows to see more details.
352+
Also, because of this, it may require some **more processing cost**.
323353

324354
### Multi-modal legs
325355

@@ -409,7 +439,8 @@ Click on each segment to analyse the details, in particular the segment duration
409439

410440
## Circuity
411441

412-
**Circuity** measures how direct or indirect a travel route is compared to the straight-line (Euclidean) distance between an origin and a destination. It reflects the efficiency of the transport network in providing direct connections.
442+
**Circuity** measures how direct or indirect a travel route is compared to the straight-line (Euclidean) distance between an origin and a destination.
443+
It reflects the efficiency of the transport network in providing direct connections.
413444

414445
The **circuity index** (C) measures how indirect a route is compared to the straight-line distance between an origin and a destination, and is defined as:
415446

@@ -428,7 +459,8 @@ In this exercise, circuity will be estimated separately for **car, walking, cycl
428459

429460
### Euclidean distances
430461

431-
First we will create lines connecting the survey locations to the university, using the `st_nearest_points()` function. This function finds returns the nearest points between two geometries, and creates a line between them.
462+
First we will create lines connecting the survey locations to the university, using the `st_nearest_points()` function.
463+
This function finds returns the nearest points between two geometries, and creates a line between them.
432464

433465
```{r}
434466
dist_euclidean = st_nearest_points(POINTS, BAIXA, pairwise = TRUE) |>
@@ -670,7 +702,8 @@ Finally, we visualized and aggregated routes using `stplanr::overline()`, combin
670702

671703
## Stop
672704

673-
`r5r` objects are still allocated to any amount of memory previously set after they are done with their calculations. In order to remove an existing `r5r` object and reallocate the memory it had been using, we use the `stop_r5` function followed by a call to Java’s garbage collector, as follows:
705+
`r5r` objects are still allocated to any amount of memory previously set after they are done with their calculations.
706+
In order to remove an existing `r5r` object and reallocate the memory it had been using, we use the `stop_r5` function followed by a call to Java’s garbage collector, as follows:
674707

675708
```{r}
676709
r5r::stop_r5(r5r_lisboa)

0 commit comments

Comments
 (0)