-
Notifications
You must be signed in to change notification settings - Fork 17
/
README.Rmd
386 lines (325 loc) · 15.2 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# gtfsrouter <a href='https://UrbanAnalyst.github.io/gtfsrouter/'><img src='man/figures/gtfsrouter.png' align="right" height=210 width=182/></a>
[![R build
status](https://github.com/UrbanAnalyst/gtfsrouter/workflows/R-CMD-check/badge.svg)](https://github.com/UrbanAnalyst/gtfsrouter/actions?query=workflow%3AR-CMD-check)
[![codecov](https://codecov.io/gh/UrbanAnalyst/gtfsrouter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/UrbanAnalyst/gtfsrouter)
[![Project Status: Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/gtfsrouter)](https://cran.r-project.org/package=gtfsrouter)
[![CRAN Downloads](http://cranlogs.r-pkg.org/badges/grand-total/gtfsrouter?color=orange)](https://cran.r-project.org/package=gtfsrouter)
**R** package for public transport routing with [GTFS (General Transit Feed
Specification)](https://developers.google.com/transit/gtfs/) data.
## Installation
You can install latest stable version of `gtfsrouter` from CRAN with:
```{r cran-installation, eval = FALSE}
install.packages ("gtfsrouter")
```
Alternatively, the current development version can be installed using any of
the following options:
```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_git ("https://git.sr.ht/~mpadge/gtfsrouter")
remotes::install_git ("https://codeberg.org/UrbanAnalyst/gtfsrouter")
remotes::install_bitbucket ("urbananalyst/gtfsrouter")
remotes::install_gitlab ("UrbanAnalyst/gtfsrouter")
remotes::install_github ("UrbanAnalyst/gtfsrouter")
```
To load the package and check the version:
```{r pkg-version, eval=TRUE}
library (gtfsrouter)
packageVersion ("gtfsrouter")
```
## Main functions
The main functions can be demonstrated with sample data included with the
package from Berlin (the "Verkehrverbund Berlin Brandenburg", or VBB). GTFS
data are always stored as `.zip` files, and these sample data can be written to
the temporary directory (`tempdir()`) of the current R session with the
function `berlin_gtfs_to_zip()`.
```{r create-zip, eval = TRUE}
filename <- berlin_gtfs_to_zip ()
print (filename)
```
For normal package use, `filename` will specify the name of a local GTFS `.zip`
file.
### gtfs_route
Given the name of a GTFS `.zip` file, `filename`, routing is as simple as the
following code:
```{r example-echo, echo = TRUE, eval = FALSE}
gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs, day = "Wed") # A pre-processing step to speed up queries
gtfs_route (gtfs,
from = "Tegel",
to = "Berlin Hauptbahnhof",
start_time = 12 * 3600 + 120
) # 12:02 in seconds
```
```{r example, echo = FALSE, message = FALSE}
gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs)
r <- gtfs_route (gtfs,
from = "Schonlein",
to = "Berlin Hauptbahnhof",
start_time = 12 * 3600 + 120
) # 12:02 in seconds
knitr::kable (r)
```
### gtfs_traveltimes
The [`gtfs_traveltimes()`
function`](https://UrbanAnalyst.github.io/gtfsrouter/reference/gtfs_traveltimes.html)
calculates minimal travel times from any nominated stop to all other stops
within a feed. It requires the two parameters of start station, and a vector of
two values specifying earliest and latest desired start times. The following
code returns the fastest travel times to all stations within the feed for
services which leave the nominated station ("Alexanderplatz") between 12:00 and
13:00 on a Monday:
```{r isochrone, eval = TRUE, message = FALSE}
gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs, day = "Monday")
x <- gtfs_traveltimes (gtfs,
from = "Alexanderplatz",
start_time_limits = c (12, 13) * 3600
)
```
The function returns a simple table detailing all stations reachable with
services departing from the nominated station and start times:
```{r iso-results1-fakey, eval = FALSE}
head (x)
```
```{r iso-results1, eval = TRUE, echo = FALSE}
knitr::kable (head (x))
```
Further details are provided in a [separate
vignette](https://UrbanAnalyst.github.io/gtfsrouter/articles/traveltimes.html).
### gtfs_transfer_table
Feeds should include a "transfers.txt" table detailing all possible transfers
between nearby stations, yet many feeds omit these tables, rendering them
unusable for routing because transfers between services can not be calculated.
The `gtfsrouter` package also includes a function,
[`gtfs_transfer_table()`](https://UrbanAnalyst.github.io/gtfsrouter/reference/gtfs_transfer_table.html),
which can calculate a transfer table for a given feed, with transfer times
calculated either using straight-line distances (the default), or using more
realistic pedestrian times routed through the underlying street network.
This function can also be used to enable routing through multiple adjacent or
overlapping GTFS feeds. The feeds need simply be merged through binding the
rows of all tables, and the resultant aggregate feed submitted to the
[`gtfs_transfer_table()`](https://UrbanAnalyst.github.io/gtfsrouter/reference/gtfs_transfer_table.html)
function. This transfer table will retain all transfers specified in the
original feeds, yet be augmented by all possible transfers between the multiple
systems up to a user-specified maximal distance. Further details of this
function are also provided in another [separate
vignette](https://UrbanAnalyst.github.io/gtfsrouter/articles/transfers.html).
## Additional Functionality
There are many ways to construct GTFS feeds. For background information, see
[`gtfs.org`](https://gtfs.org), and particularly their [GTFS
Examples](https://docs.google.com/document/d/16inL5BVcM1aU-_DcFJay_tC6Ni0wPa0nvQEstueG5k4/edit).
Feeds may include a "frequencies.txt" table which defines "service periods",
and overrides any schedule information during the specified times. The
`gtfsrouter` package includes a function,
[`frequencies_to_stop_times()`](https://UrbanAnalyst.github.io/gtfsrouter/reference/frequencies_to_stop_times.html),
to convert "frequencies.txt" tables to equivalent "stop_times.txt" entries, to
enable the feed to be used for routing.
## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [all-contributors](https://allcontributors.org) specification. Contributions of any kind are welcome!
### Code
<table>
<tr>
<td align="center">
<a href="https://github.com/mpadge">
<img src="https://avatars.githubusercontent.com/u/6697851?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/commits?author=mpadge">mpadge</a>
</td>
<td align="center">
<a href="https://github.com/AlexandraKapp">
<img src="https://avatars.githubusercontent.com/u/18367515?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/commits?author=AlexandraKapp">AlexandraKapp</a>
</td>
<td align="center">
<a href="https://github.com/stmarcin">
<img src="https://avatars.githubusercontent.com/u/11378350?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/commits?author=stmarcin">stmarcin</a>
</td>
<td align="center">
<a href="https://github.com/dhersz">
<img src="https://avatars.githubusercontent.com/u/1557047?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/commits?author=dhersz">dhersz</a>
</td>
<td align="center">
<a href="https://github.com/polettif">
<img src="https://avatars.githubusercontent.com/u/17431069?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/commits?author=polettif">polettif</a>
</td>
</tr>
</table>
### Issue Authors
<table>
<tr>
<td align="center">
<a href="https://github.com/sridharraman">
<img src="https://avatars.githubusercontent.com/u/570692?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Asridharraman">sridharraman</a>
</td>
<td align="center">
<a href="https://github.com/orlandombaa">
<img src="https://avatars.githubusercontent.com/u/48104481?u=66d48bb0e7efb664a94eace3472aa6a06960a7f4&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Aorlandombaa">orlandombaa</a>
</td>
<td align="center">
<a href="https://github.com/Maxime2506">
<img src="https://avatars.githubusercontent.com/u/54989587?u=6d2c848ee0c7d8a2841d47791c30eec1cab35470&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3AMaxime2506">Maxime2506</a>
</td>
<td align="center">
<a href="https://github.com/chinhqho">
<img src="https://avatars.githubusercontent.com/u/47441312?u=577d1dca03b4bb904bb45f1e6205b11144c900cd&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Achinhqho">chinhqho</a>
</td>
<td align="center">
<a href="https://github.com/federicotallis">
<img src="https://avatars.githubusercontent.com/u/25511806?u=f074beb69d1984dad98483c5b43a4d42402542dc&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Afedericotallis">federicotallis</a>
</td>
<td align="center">
<a href="https://github.com/rafapereirabr">
<img src="https://avatars.githubusercontent.com/u/7448421?u=01aed495e612154e54be4c51221e706cdff7779d&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Arafapereirabr">rafapereirabr</a>
</td>
<td align="center">
<a href="https://github.com/dcooley">
<img src="https://avatars.githubusercontent.com/u/8093396?u=2c8d9162f246d90d433034d212b29a19e0f245c1&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Adcooley">dcooley</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/bernd886">
<img src="https://avatars.githubusercontent.com/u/56547410?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Abernd886">bernd886</a>
</td>
<td align="center">
<a href="https://github.com/stefan-overkamp">
<img src="https://avatars.githubusercontent.com/u/55497288?u=946d42a5f3d068a44b43ee8e5f5fd5065d968419&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Astefan-overkamp">stefan-overkamp</a>
</td>
<td align="center">
<a href="https://github.com/luukvdmeer">
<img src="https://avatars.githubusercontent.com/u/26540305?u=c576e87314499815cbf698b7781ee58fd1d773e2&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Aluukvdmeer">luukvdmeer</a>
</td>
<td align="center">
<a href="https://github.com/szaboildi">
<img src="https://avatars.githubusercontent.com/u/10348398?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Aszaboildi">szaboildi</a>
</td>
<td align="center">
<a href="https://github.com/cseveren">
<img src="https://avatars.githubusercontent.com/u/30906872?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Acseveren">cseveren</a>
</td>
<td align="center">
<a href="https://github.com/jh0ker">
<img src="https://avatars.githubusercontent.com/u/3945220?u=dcb262dbf7fe448a8b24b673bcb995e3311f08d4&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Ajh0ker">jh0ker</a>
</td>
<td align="center">
<a href="https://github.com/zamirD123">
<img src="https://avatars.githubusercontent.com/u/69770500?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3AzamirD123">zamirD123</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/viajerus">
<img src="https://avatars.githubusercontent.com/u/63015973?u=e85734d18801b607316ea25b24624da6762862c3&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Aviajerus">viajerus</a>
</td>
<td align="center">
<a href="https://github.com/jmertic">
<img src="https://avatars.githubusercontent.com/u/296737?u=fc986558ce47707906a0d0e5affd0f621859026c&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Ajmertic">jmertic</a>
</td>
<td align="center">
<a href="https://github.com/5balls">
<img src="https://avatars.githubusercontent.com/u/28660096?u=608617a38222ee398a2fc3d68ff04c90b2f49efe&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3A5balls">5balls</a>
</td>
<td align="center">
<a href="https://github.com/pteridin">
<img src="https://avatars.githubusercontent.com/u/29350560?u=a3a45577202757768e14a8a2d59a31c9d92a32db&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3Apteridin">pteridin</a>
</td>
<td align="center">
<a href="https://github.com/FlxPo">
<img src="https://avatars.githubusercontent.com/u/5145583?u=cbd02ee0a0fa0447429f38bd7e3a1da57c841239&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+author%3AFlxPo">FlxPo</a>
</td>
</tr>
</table>
### Issue Contributors
<table>
<tr>
<td align="center">
<a href="https://github.com/tbuckl">
<img src="https://avatars.githubusercontent.com/u/98956?u=9580c2ee3c03cbbe44ac8180b0f6a6725b0415f0&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3Atbuckl">tbuckl</a>
</td>
<td align="center">
<a href="https://github.com/tuesd4y">
<img src="https://avatars.githubusercontent.com/u/13107179?u=cfcc7852d1bed6e2b17fa3f985cebf743c43b299&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3Atuesd4y">tuesd4y</a>
</td>
<td align="center">
<a href="https://github.com/Robinlovelace">
<img src="https://avatars.githubusercontent.com/u/1825120?u=461318c239e721dc40668e4b0ce6cc47731328ac&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3ARobinlovelace">Robinlovelace</a>
</td>
<td align="center">
<a href="https://github.com/loanho23">
<img src="https://avatars.githubusercontent.com/u/48426365?u=36727e1ed27b3b6206fb922c47544ef249fad83d&v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3Aloanho23">loanho23</a>
</td>
<td align="center">
<a href="https://github.com/abyrd">
<img src="https://avatars.githubusercontent.com/u/112871?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3Aabyrd">abyrd</a>
</td>
<td align="center">
<a href="https://github.com/hansmib">
<img src="https://avatars.githubusercontent.com/u/52329319?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/UrbanAnalyst/gtfsrouter/issues?q=is%3Aissue+commenter%3Ahansmib">hansmib</a>
</td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->