gtfs 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +14 -19
- package/.husky/pre-commit +4 -0
- package/@types/index.d.ts +269 -0
- package/@types/tests.ts +26 -0
- package/@types/tsconfig.json +17 -0
- package/CHANGELOG.md +182 -1
- package/README.md +168 -149
- package/bin/gtfs-export.js +4 -5
- package/bin/gtfs-import.js +6 -7
- package/config-sample-full.json +2 -7
- package/docs/images/node-gtfs-logo.svg +18 -0
- package/lib/db.js +63 -12
- package/lib/export.js +27 -13
- package/lib/file-utils.js +26 -9
- package/lib/geojson-utils.js +51 -38
- package/lib/gtfs/agencies.js +15 -4
- package/lib/gtfs/attributions.js +15 -4
- package/lib/gtfs/calendar-dates.js +15 -4
- package/lib/gtfs/calendars.js +15 -4
- package/lib/gtfs/fare-attributes.js +15 -4
- package/lib/gtfs/fare-rules.js +15 -4
- package/lib/gtfs/feed-info.js +15 -4
- package/lib/gtfs/frequencies.js +15 -4
- package/lib/gtfs/levels.js +15 -4
- package/lib/gtfs/pathways.js +15 -4
- package/lib/gtfs/routes.js +22 -6
- package/lib/gtfs/shapes.js +59 -23
- package/lib/gtfs/stop-times.js +15 -4
- package/lib/gtfs/stops.js +57 -23
- package/lib/gtfs/transfers.js +15 -4
- package/lib/gtfs/translations.js +15 -4
- package/lib/gtfs/trips.js +15 -4
- package/lib/gtfs-ride/board-alights.js +15 -4
- package/lib/gtfs-ride/ride-feed-infos.js +15 -4
- package/lib/gtfs-ride/rider-trips.js +15 -4
- package/lib/gtfs-ride/riderships.js +15 -4
- package/lib/gtfs-ride/trip-capacities.js +15 -4
- package/lib/import.js +203 -128
- package/lib/log-utils.js +8 -4
- package/lib/non-standard/directions.js +15 -4
- package/lib/non-standard/stop-attributes.js +15 -4
- package/lib/non-standard/timetable-notes-references.js +15 -4
- package/lib/non-standard/timetable-notes.js +15 -4
- package/lib/non-standard/timetable-pages.js +15 -4
- package/lib/non-standard/timetable-stop-order.js +15 -4
- package/lib/non-standard/timetables.js +15 -4
- package/lib/utils.js +26 -12
- package/models/gtfs/agency.js +11 -11
- package/models/gtfs/attributions.js +14 -14
- package/models/gtfs/calendar-dates.js +7 -7
- package/models/gtfs/calendar.js +12 -12
- package/models/gtfs/fare-attributes.js +9 -9
- package/models/gtfs/fare-rules.js +8 -8
- package/models/gtfs/feed-info.js +12 -12
- package/models/gtfs/frequencies.js +10 -10
- package/models/gtfs/levels.js +5 -5
- package/models/gtfs/pathways.js +14 -14
- package/models/gtfs/routes.js +14 -14
- package/models/gtfs/shapes.js +8 -8
- package/models/gtfs/stop-times.js +17 -17
- package/models/gtfs/stops.js +17 -17
- package/models/gtfs/transfers.js +7 -7
- package/models/gtfs/translations.js +10 -10
- package/models/gtfs/trips.js +12 -12
- package/models/gtfs-ride/board-alight.js +24 -24
- package/models/gtfs-ride/ride-feed-info.js +8 -8
- package/models/gtfs-ride/rider-trip.js +21 -21
- package/models/gtfs-ride/ridership.js +23 -23
- package/models/gtfs-ride/trip-capacity.js +10 -10
- package/models/models.js +1 -1
- package/models/non-standard/directions.js +6 -6
- package/models/non-standard/stop-attributes.js +5 -5
- package/models/non-standard/timetable-notes-references.js +9 -9
- package/models/non-standard/timetable-notes.js +5 -5
- package/models/non-standard/timetable-pages.js +5 -5
- package/models/non-standard/timetable-stop-order.js +6 -6
- package/models/non-standard/timetables.js +27 -27
- package/package.json +35 -13
- package/test/mocha/export-gtfs.js +74 -44
- package/test/mocha/get-agencies.js +20 -14
- package/test/mocha/get-attributions.js +10 -4
- package/test/mocha/get-board-alights.js +10 -4
- package/test/mocha/get-calendar-dates.js +31 -24
- package/test/mocha/get-calendars.js +17 -11
- package/test/mocha/get-db.js +71 -5
- package/test/mocha/get-directions.js +10 -4
- package/test/mocha/get-fare-attributes.js +12 -6
- package/test/mocha/get-fare-rules.js +17 -13
- package/test/mocha/get-feed-info.js +10 -4
- package/test/mocha/get-frequencies.js +10 -4
- package/test/mocha/get-levels.js +4 -4
- package/test/mocha/get-pathways.js +10 -4
- package/test/mocha/get-ride-feed-infos.js +9 -3
- package/test/mocha/get-rider-trips.js +10 -4
- package/test/mocha/get-riderships.js +10 -4
- package/test/mocha/get-routes.js +12 -16
- package/test/mocha/get-shapes-as-geojson.js +12 -6
- package/test/mocha/get-shapes.js +31 -39
- package/test/mocha/get-stop-attributes.js +10 -4
- package/test/mocha/get-stops-as-geojson.js +11 -5
- package/test/mocha/get-stops.js +62 -51
- package/test/mocha/get-stoptimes.js +18 -10
- package/test/mocha/get-timetable-pages.js +10 -4
- package/test/mocha/get-timetable-stop-orders.js +10 -4
- package/test/mocha/get-timetables.js +10 -4
- package/test/mocha/get-transfers.js +10 -4
- package/test/mocha/get-translations.js +10 -4
- package/test/mocha/get-trip-capacities.js +10 -4
- package/test/mocha/get-trips.js +6 -6
- package/test/mocha/import-gtfs.js +63 -46
- package/test/test-config.js +9 -4
package/README.md
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
➡️
|
|
3
|
+
<a href="#installation">Installation</a> |
|
|
4
|
+
<a href="#quick-start">Quick Start</a> |
|
|
5
|
+
<a href="#typescript-support">TypeScript Support</a> |
|
|
6
|
+
<a href="#configuration">Configuration</a> |
|
|
7
|
+
<a href="#query-methods">Query Methods</a>
|
|
8
|
+
⬅️
|
|
9
|
+
<br /><br />
|
|
10
|
+
<img src="docs/images/node-gtfs-logo.svg" alt="node-GTFS" />
|
|
11
|
+
<br /><br />
|
|
12
|
+
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/v/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/dm/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
14
|
+
<a href="https://github.com/BlinkTagInc/node-gtfs/actions?query=workflow%3A%22Node+CI%22"><img src="https://img.shields.io/github/workflow/status/BlinkTagInc/node-gtfs/Node%20CI.svg" alt="CircleCI" style="max-width: 100%;"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
16
|
+
<br /><br />
|
|
17
|
+
Import and Export GTFS transit data into SQLite. Query or change routes, stops, times, fares and more.
|
|
18
|
+
<br /><br />
|
|
19
|
+
<a href="https://nodei.co/npm/gtfs/" rel="nofollow"><img src="https://nodei.co/npm/gtfs.png?downloads=true" alt="NPM" style="max-width: 100%;"></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<hr>
|
|
10
23
|
|
|
11
24
|
`node-GTFS` loads transit data in [GTFS format](https://developers.google.com/transit/) into a SQLite database and provides some methods to query for agencies, routes, stops, times, fares, calendars and other GTFS data. It also offers spatial queries to find nearby stops, routes and agencies and can convert stops and shapes to geoJSON format.
|
|
12
25
|
|
|
13
26
|
Additionally, this library can export data from the SQLite database back into GTFS (csv) format.
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Example Application
|
|
18
|
-
|
|
19
|
-
The [GTFS-to-HTML](https://gtfstohtml.com) app uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library and is used by over a dozen transit agencies to generate the timetables on their websites.
|
|
28
|
+
You can use it as a [command-line tool](#command-line-examples) or as a [node.js module](#code-example).
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
The [GTFS-to-chart](https://github.com/blinktaginc/gtfs-to-chart) app generates a stringline chart in D3 for all trips for a specific route using data from an agency's GTFS. It uses `node-gtfs` for downloading, importing and querying GTFS data.
|
|
24
|
-
|
|
25
|
-
The [GTFS-Text-to-Speech](https://github.com/blinktaginc/node-gtfs-tts) app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.
|
|
30
|
+
This library has three parts: the [GTFS import script](#gtfs-import-script), the [query methods](#query-methods) and the [GTFS export script](#gtfs-export-script)
|
|
26
31
|
|
|
27
32
|
## Installation
|
|
28
33
|
|
|
@@ -32,16 +37,18 @@ If you would like to use this library as a command-line utility, you can install
|
|
|
32
37
|
|
|
33
38
|
If you are using this as a node module as part of an application, you can include it in your project's `package.json` file.
|
|
34
39
|
|
|
35
|
-
##
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Command-line examples
|
|
36
43
|
|
|
37
44
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
38
45
|
|
|
39
|
-
or
|
|
40
|
-
|
|
46
|
+
or
|
|
47
|
+
|
|
41
48
|
gtfs-import --gtfsPath /path/to/your/gtfs.zip
|
|
42
49
|
|
|
43
|
-
or
|
|
44
|
-
|
|
50
|
+
or
|
|
51
|
+
|
|
45
52
|
gtfs-import --gtfsPath /path/to/your/unzipped/gtfs
|
|
46
53
|
|
|
47
54
|
or
|
|
@@ -50,21 +57,44 @@ or
|
|
|
50
57
|
|
|
51
58
|
gtfs-export --configPath /path/to/your/custom-config.json
|
|
52
59
|
|
|
53
|
-
|
|
60
|
+
### Code example
|
|
54
61
|
|
|
55
62
|
```js
|
|
56
63
|
import { importGtfs } from 'gtfs';
|
|
57
64
|
import { readFile } from 'fs/promises';
|
|
58
|
-
const config = JSON.parse(
|
|
65
|
+
const config = JSON.parse(
|
|
66
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
67
|
+
);
|
|
59
68
|
|
|
60
69
|
importGtfs(config)
|
|
61
|
-
.then(() => {
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
.catch(err => {
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
```
|
|
70
|
+
.then(() => {
|
|
71
|
+
console.log('Import Successful');
|
|
72
|
+
})
|
|
73
|
+
.catch((err) => {
|
|
74
|
+
console.error(err);
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Example Applications
|
|
79
|
+
|
|
80
|
+
<table>
|
|
81
|
+
<tr>
|
|
82
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-html/raw/master/www/static/img/gtfs-to-html-logo.svg" alt="GTFS-to-HTML" width="200"></td>
|
|
83
|
+
<td><a href="https://gtfstohtml.com">GTFS-to-HTML</a> uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library and is used by over a dozen transit agencies to generate the timetables on their websites.</td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-geojson/raw/master/docs/images/gtfs-to-geojson-logo.svg" alt="GTFS-to-geojson" width="200"></td>
|
|
87
|
+
<td><a href="https://github.com/blinktaginc/gtfs-to-geojson">GTFS-to-geojson</a> creates geoJSON files for transit routes for use in mapping. It uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library.</td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-chart/raw/master/docs/images/gtfs-to-chart-logo.svg" alt="GTFS-to-Chart" width="200"></td>
|
|
91
|
+
<td><a href="https://github.com/blinktaginc/gtfs-to-chart">GTFS-to-chart</a> generates a stringline chart in D3 for all trips for a specific route using data from an agency's GTFS. It uses `node-gtfs` for downloading, importing and querying GTFS data.</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-tts/raw/main/docs/images/gtfs-tts-logo.svg" alt="GTFS-TTS" width="200"></td>
|
|
95
|
+
<td><a href="https://github.com/blinktaginc/gtfs-tts">GTFS-Text-to-Speech</a> app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</table>
|
|
68
98
|
|
|
69
99
|
## Command Line Usage
|
|
70
100
|
|
|
@@ -86,29 +116,33 @@ Specify a local path to GTFS, either zipped or unzipped.
|
|
|
86
116
|
|
|
87
117
|
gtfs-import --gtfsPath /path/to/your/gtfs.zip
|
|
88
118
|
|
|
89
|
-
or
|
|
90
|
-
|
|
119
|
+
or
|
|
120
|
+
|
|
91
121
|
gtfs-import --gtfsPath /path/to/your/unzipped/gtfs
|
|
92
122
|
|
|
93
123
|
`gtfsUrl`
|
|
94
124
|
|
|
95
125
|
Specify a URL to a zipped GTFS file.
|
|
96
|
-
|
|
126
|
+
|
|
97
127
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
98
128
|
|
|
99
|
-
##
|
|
129
|
+
## TypeScript Support
|
|
130
|
+
|
|
131
|
+
Basic TypeScript typings are included with this library. Please [open an issue](https://github.com/blinktaginc/node-gtfs/issues) if you find any inconsistencies between the declared types and underlying code.
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
100
134
|
|
|
101
135
|
Copy `config-sample.json` to `config.json` and then add your projects configuration to `config.json`.
|
|
102
136
|
|
|
103
137
|
cp config-sample.json config.json
|
|
104
138
|
|
|
105
|
-
| option
|
|
106
|
-
|
|
|
107
|
-
| [`agencies`](#agencies)
|
|
108
|
-
| [`csvOptions`](#csvOptions) | object
|
|
109
|
-
| [`exportPath`](#exportPath) | string
|
|
110
|
-
| [`sqlitePath`](#sqlitePath) | string
|
|
111
|
-
| [`verbose`](#verbose)
|
|
139
|
+
| option | type | description |
|
|
140
|
+
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| [`agencies`](#agencies) | array | An array of GTFS files to be imported. |
|
|
142
|
+
| [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
|
|
143
|
+
| [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
|
|
144
|
+
| [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
|
|
145
|
+
| [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
|
|
112
146
|
|
|
113
147
|
### agencies
|
|
114
148
|
|
|
@@ -120,7 +154,8 @@ To find an agency's GTFS file, visit [transitfeeds.com](http://transitfeeds.com)
|
|
|
120
154
|
URL from the agency's website or you can use a URL generated from the transitfeeds.com
|
|
121
155
|
API along with your API token.
|
|
122
156
|
|
|
123
|
-
|
|
157
|
+
- Specify a download URL:
|
|
158
|
+
|
|
124
159
|
```json
|
|
125
160
|
{
|
|
126
161
|
"agencies": [
|
|
@@ -131,7 +166,8 @@ API along with your API token.
|
|
|
131
166
|
}
|
|
132
167
|
```
|
|
133
168
|
|
|
134
|
-
|
|
169
|
+
- Specify a download URL with custom headers:
|
|
170
|
+
|
|
135
171
|
```json
|
|
136
172
|
{
|
|
137
173
|
"agencies": [
|
|
@@ -140,13 +176,14 @@ API along with your API token.
|
|
|
140
176
|
"headers": {
|
|
141
177
|
"Content-Type": "application/json",
|
|
142
178
|
"Authorization": "bearer 1234567890"
|
|
143
|
-
}
|
|
179
|
+
}
|
|
144
180
|
}
|
|
145
181
|
]
|
|
146
182
|
}
|
|
147
183
|
```
|
|
148
184
|
|
|
149
|
-
|
|
185
|
+
- Specify a path to a zipped GTFS file:
|
|
186
|
+
|
|
150
187
|
```json
|
|
151
188
|
{
|
|
152
189
|
"agencies": [
|
|
@@ -156,7 +193,9 @@ API along with your API token.
|
|
|
156
193
|
]
|
|
157
194
|
}
|
|
158
195
|
```
|
|
159
|
-
|
|
196
|
+
|
|
197
|
+
- Specify a path to an unzipped GTFS file:
|
|
198
|
+
|
|
160
199
|
```json
|
|
161
200
|
{
|
|
162
201
|
"agencies": [
|
|
@@ -167,23 +206,20 @@ API along with your API token.
|
|
|
167
206
|
}
|
|
168
207
|
```
|
|
169
208
|
|
|
170
|
-
|
|
209
|
+
- Exclude files - if you don't want all GTFS files to be imported, you can specify an array of files to exclude.
|
|
171
210
|
|
|
172
211
|
```json
|
|
173
212
|
{
|
|
174
213
|
"agencies": [
|
|
175
214
|
{
|
|
176
215
|
"path": "/path/to/the/unzipped/gtfs/",
|
|
177
|
-
"exclude": [
|
|
178
|
-
"shapes",
|
|
179
|
-
"stops"
|
|
180
|
-
]
|
|
216
|
+
"exclude": ["shapes", "stops"]
|
|
181
217
|
}
|
|
182
218
|
]
|
|
183
219
|
}
|
|
184
220
|
```
|
|
185
221
|
|
|
186
|
-
|
|
222
|
+
- Specify multiple agencies to be imported into the same database
|
|
187
223
|
|
|
188
224
|
```json
|
|
189
225
|
{
|
|
@@ -239,7 +275,7 @@ See [full list of options](https://csv.js.org/parse/options/).
|
|
|
239
275
|
}
|
|
240
276
|
```
|
|
241
277
|
|
|
242
|
-
If you want to route logs to a custom function, you can pass a function that takes a single `text` argument as `logFunction`. This can't be defined in `config.json` but instead passed in a config object to `importGtfs()`.
|
|
278
|
+
If you want to route logs to a custom function, you can pass a function that takes a single `text` argument as `logFunction`. This can't be defined in `config.json` but instead passed in a config object to `importGtfs()`. For example:
|
|
243
279
|
|
|
244
280
|
```js
|
|
245
281
|
import { importGtfs } from 'gtfs';
|
|
@@ -248,15 +284,13 @@ const config = {
|
|
|
248
284
|
agencies: [
|
|
249
285
|
{
|
|
250
286
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
251
|
-
exclude: [
|
|
252
|
-
|
|
253
|
-
]
|
|
254
|
-
}
|
|
287
|
+
exclude: ['shapes'],
|
|
288
|
+
},
|
|
255
289
|
],
|
|
256
|
-
logFunction: function(text) {
|
|
290
|
+
logFunction: function (text) {
|
|
257
291
|
// Do something with the logs here, like save it or send it somewhere
|
|
258
292
|
console.log(text);
|
|
259
|
-
}
|
|
293
|
+
},
|
|
260
294
|
};
|
|
261
295
|
|
|
262
296
|
importGtfs(config);
|
|
@@ -282,15 +316,17 @@ Use `importGtfs()` in your code to run an import of a GTFS file specified in a c
|
|
|
282
316
|
import { importGtfs } from 'gtfs';
|
|
283
317
|
import { readFile } from 'fs/promises';
|
|
284
318
|
|
|
285
|
-
const config = JSON.parse(
|
|
319
|
+
const config = JSON.parse(
|
|
320
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
321
|
+
);
|
|
286
322
|
|
|
287
323
|
importGtfs(config)
|
|
288
|
-
.then(() => {
|
|
289
|
-
|
|
290
|
-
})
|
|
291
|
-
.catch(err => {
|
|
292
|
-
|
|
293
|
-
});
|
|
324
|
+
.then(() => {
|
|
325
|
+
console.log('Import Successful');
|
|
326
|
+
})
|
|
327
|
+
.catch((err) => {
|
|
328
|
+
console.error(err);
|
|
329
|
+
});
|
|
294
330
|
```
|
|
295
331
|
|
|
296
332
|
Configuration can be a JSON object in your code
|
|
@@ -303,20 +339,18 @@ const config = {
|
|
|
303
339
|
agencies: [
|
|
304
340
|
{
|
|
305
341
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
306
|
-
exclude: [
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
]
|
|
342
|
+
exclude: ['shapes'],
|
|
343
|
+
},
|
|
344
|
+
],
|
|
311
345
|
};
|
|
312
346
|
|
|
313
347
|
importGtfs(config)
|
|
314
|
-
.then(() => {
|
|
315
|
-
|
|
316
|
-
})
|
|
317
|
-
.catch(err => {
|
|
318
|
-
|
|
319
|
-
});
|
|
348
|
+
.then(() => {
|
|
349
|
+
console.log('Import Successful');
|
|
350
|
+
})
|
|
351
|
+
.catch((err) => {
|
|
352
|
+
console.error(err);
|
|
353
|
+
});
|
|
320
354
|
```
|
|
321
355
|
|
|
322
356
|
## `gtfs-export` Script
|
|
@@ -340,11 +374,13 @@ By default, it will look for a `config.json` file in the project root. To specif
|
|
|
340
374
|
### Command Line options
|
|
341
375
|
|
|
342
376
|
#### Specify path to config JSON file
|
|
377
|
+
|
|
343
378
|
You can specify the path to a config file to be used by the export script.
|
|
344
379
|
|
|
345
380
|
gtfs-export --configPath /path/to/your/custom-config.json
|
|
346
381
|
|
|
347
382
|
#### Show help
|
|
383
|
+
|
|
348
384
|
Show all command line options
|
|
349
385
|
|
|
350
386
|
gtfs-export --help
|
|
@@ -361,20 +397,18 @@ const config = {
|
|
|
361
397
|
agencies: [
|
|
362
398
|
{
|
|
363
399
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
364
|
-
exclude: [
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
]
|
|
400
|
+
exclude: ['shapes'],
|
|
401
|
+
},
|
|
402
|
+
],
|
|
369
403
|
};
|
|
370
404
|
|
|
371
405
|
exportGtfs(config)
|
|
372
|
-
.then(() => {
|
|
373
|
-
|
|
374
|
-
})
|
|
375
|
-
.catch(err => {
|
|
376
|
-
|
|
377
|
-
});
|
|
406
|
+
.then(() => {
|
|
407
|
+
console.log('Export Successful');
|
|
408
|
+
})
|
|
409
|
+
.catch((err) => {
|
|
410
|
+
console.error(err);
|
|
411
|
+
});
|
|
378
412
|
```
|
|
379
413
|
|
|
380
414
|
## Query Methods
|
|
@@ -390,19 +424,15 @@ For example, to get a list of all routes with just `route_id`, `route_short_name
|
|
|
390
424
|
```js
|
|
391
425
|
import { openDb, getRoutes } from 'gtfs';
|
|
392
426
|
import { readFile } from 'fs/promises';
|
|
393
|
-
const config = JSON.parse(
|
|
427
|
+
const config = JSON.parse(
|
|
428
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
429
|
+
);
|
|
394
430
|
|
|
395
431
|
const db = await openDb(config);
|
|
396
432
|
const routes = await getRoutes(
|
|
397
433
|
{},
|
|
398
|
-
[
|
|
399
|
-
|
|
400
|
-
'route_short_name',
|
|
401
|
-
'route_color'
|
|
402
|
-
],
|
|
403
|
-
[
|
|
404
|
-
['route_short_name', 'ASC']
|
|
405
|
-
]
|
|
434
|
+
['route_id', 'route_short_name', 'route_color'],
|
|
435
|
+
[['route_short_name', 'ASC']]
|
|
406
436
|
);
|
|
407
437
|
```
|
|
408
438
|
|
|
@@ -411,16 +441,16 @@ To get a list of all trip_ids for a specific route:
|
|
|
411
441
|
```js
|
|
412
442
|
import { openDb, getTrips } from 'gtfs';
|
|
413
443
|
import { readFile } from 'fs/promises';
|
|
414
|
-
const config = JSON.parse(
|
|
444
|
+
const config = JSON.parse(
|
|
445
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
446
|
+
);
|
|
415
447
|
|
|
416
448
|
const db = await openDb(config);
|
|
417
449
|
const trips = await getTrips(
|
|
418
450
|
{
|
|
419
|
-
route_id: '123'
|
|
451
|
+
route_id: '123',
|
|
420
452
|
},
|
|
421
|
-
[
|
|
422
|
-
'trip_id'
|
|
423
|
-
]
|
|
453
|
+
['trip_id']
|
|
424
454
|
);
|
|
425
455
|
```
|
|
426
456
|
|
|
@@ -469,7 +499,7 @@ getAgencies();
|
|
|
469
499
|
|
|
470
500
|
// Get a specific agency
|
|
471
501
|
getAgencies({
|
|
472
|
-
agency_id: 'caltrain'
|
|
502
|
+
agency_id: 'caltrain',
|
|
473
503
|
});
|
|
474
504
|
```
|
|
475
505
|
|
|
@@ -485,7 +515,7 @@ getAttributions();
|
|
|
485
515
|
|
|
486
516
|
// Get a specific attribution
|
|
487
517
|
getAttributions({
|
|
488
|
-
attribution_id: '123'
|
|
518
|
+
attribution_id: '123',
|
|
489
519
|
});
|
|
490
520
|
```
|
|
491
521
|
|
|
@@ -497,17 +527,11 @@ Queries routes and returns a promise. The result of the promise is an array of r
|
|
|
497
527
|
import { getRoutes } from 'gtfs';
|
|
498
528
|
|
|
499
529
|
// Get all routes, sorted by route_short_name
|
|
500
|
-
getRoutes(
|
|
501
|
-
{},
|
|
502
|
-
[],
|
|
503
|
-
[
|
|
504
|
-
['route_short_name', 'ASC']
|
|
505
|
-
]
|
|
506
|
-
);
|
|
530
|
+
getRoutes({}, [], [['route_short_name', 'ASC']]);
|
|
507
531
|
|
|
508
532
|
// Get a specific route
|
|
509
533
|
getRoutes({
|
|
510
|
-
route_id: 'Lo-16APR'
|
|
534
|
+
route_id: 'Lo-16APR',
|
|
511
535
|
});
|
|
512
536
|
```
|
|
513
537
|
|
|
@@ -519,12 +543,10 @@ import { getRoutes } from 'gtfs';
|
|
|
519
543
|
// Get routes that serve a specific stop, sorted by `stop_name`.
|
|
520
544
|
getRoutes(
|
|
521
545
|
{
|
|
522
|
-
stop_id: '70011'
|
|
546
|
+
stop_id: '70011',
|
|
523
547
|
},
|
|
524
548
|
[],
|
|
525
|
-
[
|
|
526
|
-
['stop_name', 'ASC']
|
|
527
|
-
]
|
|
549
|
+
[['stop_name', 'ASC']]
|
|
528
550
|
);
|
|
529
551
|
```
|
|
530
552
|
|
|
@@ -540,7 +562,7 @@ getStops();
|
|
|
540
562
|
|
|
541
563
|
// Get a specific stop by stop_id
|
|
542
564
|
getStops({
|
|
543
|
-
stop_id: '70011'
|
|
565
|
+
stop_id: '70011',
|
|
544
566
|
});
|
|
545
567
|
```
|
|
546
568
|
|
|
@@ -551,7 +573,7 @@ import { getRoutes } from 'gtfs';
|
|
|
551
573
|
|
|
552
574
|
// Get all stops for a specific route
|
|
553
575
|
getStops({
|
|
554
|
-
route_id: 'Lo-16APR'
|
|
576
|
+
route_id: 'Lo-16APR',
|
|
555
577
|
});
|
|
556
578
|
```
|
|
557
579
|
|
|
@@ -562,7 +584,7 @@ import { getRoutes } from 'gtfs';
|
|
|
562
584
|
|
|
563
585
|
// Get all stops for a specific trip
|
|
564
586
|
getStops({
|
|
565
|
-
trip_id: '37a'
|
|
587
|
+
trip_id: '37a',
|
|
566
588
|
});
|
|
567
589
|
```
|
|
568
590
|
|
|
@@ -578,7 +600,7 @@ getStopsAsGeoJSON();
|
|
|
578
600
|
|
|
579
601
|
// Get all stops for a specific route as geoJSON
|
|
580
602
|
getStopsAsGeoJSON({
|
|
581
|
-
route_id: 'Lo-16APR'
|
|
603
|
+
route_id: 'Lo-16APR',
|
|
582
604
|
});
|
|
583
605
|
```
|
|
584
606
|
|
|
@@ -594,24 +616,22 @@ getStoptimes();
|
|
|
594
616
|
|
|
595
617
|
// Get all stoptimes for a specific stop
|
|
596
618
|
getStoptimes({
|
|
597
|
-
stop_id: '70011'
|
|
619
|
+
stop_id: '70011',
|
|
598
620
|
});
|
|
599
621
|
|
|
600
622
|
// Get all stoptimes for a specific trip, sorted by stop_sequence
|
|
601
623
|
getStoptimes(
|
|
602
624
|
{
|
|
603
|
-
trip_id: '37a'
|
|
625
|
+
trip_id: '37a',
|
|
604
626
|
},
|
|
605
627
|
[],
|
|
606
|
-
[
|
|
607
|
-
['stop_sequence', 'ASC']
|
|
608
|
-
]
|
|
628
|
+
[['stop_sequence', 'ASC']]
|
|
609
629
|
);
|
|
610
630
|
|
|
611
631
|
// Get all stoptimes for a specific stop and service_id
|
|
612
632
|
getStoptimes({
|
|
613
633
|
stop_id: '70011',
|
|
614
|
-
service_id: 'CT-16APR-Caltrain-Weekday-01'
|
|
634
|
+
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
615
635
|
});
|
|
616
636
|
```
|
|
617
637
|
|
|
@@ -657,7 +677,7 @@ getShapes();
|
|
|
657
677
|
```
|
|
658
678
|
|
|
659
679
|
`getShapes` allows passing a `route_id` in the query and it will query trips to find all shapes served by that `route_id`.
|
|
660
|
-
|
|
680
|
+
|
|
661
681
|
```js
|
|
662
682
|
import { getShapes } from 'gtfs';
|
|
663
683
|
|
|
@@ -674,7 +694,7 @@ import { getShapes } from 'gtfs';
|
|
|
674
694
|
|
|
675
695
|
// Get all shapes for a specific trip_id
|
|
676
696
|
getShapes({
|
|
677
|
-
trip_id: '37a'
|
|
697
|
+
trip_id: '37a',
|
|
678
698
|
});
|
|
679
699
|
```
|
|
680
700
|
|
|
@@ -703,17 +723,17 @@ getShapesAsGeoJSON();
|
|
|
703
723
|
|
|
704
724
|
// Get geoJSON of stops along a specific route
|
|
705
725
|
getShapesAsGeoJSON({
|
|
706
|
-
route_id: 'Lo-16APR'
|
|
726
|
+
route_id: 'Lo-16APR',
|
|
707
727
|
});
|
|
708
728
|
|
|
709
729
|
// Get geoJSON of stops for a specific trip
|
|
710
730
|
getShapesAsGeoJSON({
|
|
711
|
-
trip_id: '37a'
|
|
731
|
+
trip_id: '37a',
|
|
712
732
|
});
|
|
713
733
|
|
|
714
734
|
// Get geoJSON of stops for a specific `service_id`
|
|
715
735
|
getShapesAsGeoJSON({
|
|
716
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
736
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
717
737
|
});
|
|
718
738
|
```
|
|
719
739
|
|
|
@@ -729,7 +749,7 @@ getCalendars();
|
|
|
729
749
|
|
|
730
750
|
// Get calendars for a specific `service_id`
|
|
731
751
|
getCalendars({
|
|
732
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
752
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
733
753
|
});
|
|
734
754
|
```
|
|
735
755
|
|
|
@@ -745,7 +765,7 @@ getCalendarDates();
|
|
|
745
765
|
|
|
746
766
|
// Get calendar_dates for a specific `service_id`
|
|
747
767
|
getCalendarDates({
|
|
748
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
768
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
749
769
|
});
|
|
750
770
|
```
|
|
751
771
|
|
|
@@ -761,7 +781,7 @@ getFareAttributes();
|
|
|
761
781
|
|
|
762
782
|
// Get `fare_attributes` for a specific `fare_id`
|
|
763
783
|
getFareAttributes({
|
|
764
|
-
fare_id: '123'
|
|
784
|
+
fare_id: '123',
|
|
765
785
|
});
|
|
766
786
|
```
|
|
767
787
|
|
|
@@ -777,7 +797,7 @@ getFareRules();
|
|
|
777
797
|
|
|
778
798
|
// Get fare_rules for a specific route
|
|
779
799
|
getFareRules({
|
|
780
|
-
route_id: 'Lo-16APR'
|
|
800
|
+
route_id: 'Lo-16APR',
|
|
781
801
|
});
|
|
782
802
|
```
|
|
783
803
|
|
|
@@ -804,7 +824,7 @@ getFrequencies();
|
|
|
804
824
|
|
|
805
825
|
// Get frequencies for a specific trip
|
|
806
826
|
getFrequencies({
|
|
807
|
-
trip_id: '1234'
|
|
827
|
+
trip_id: '1234',
|
|
808
828
|
});
|
|
809
829
|
```
|
|
810
830
|
|
|
@@ -842,7 +862,7 @@ getTransfers();
|
|
|
842
862
|
|
|
843
863
|
// Get transfers for a specific stop
|
|
844
864
|
getTransfers({
|
|
845
|
-
from_stop_id: '1234'
|
|
865
|
+
from_stop_id: '1234',
|
|
846
866
|
});
|
|
847
867
|
```
|
|
848
868
|
|
|
@@ -869,13 +889,13 @@ getDirections();
|
|
|
869
889
|
|
|
870
890
|
// Get directions for a specific route
|
|
871
891
|
getDirections({
|
|
872
|
-
route_id: '1234'
|
|
892
|
+
route_id: '1234',
|
|
873
893
|
});
|
|
874
894
|
|
|
875
895
|
// Get directions for a specific route and direction
|
|
876
896
|
getDirections({
|
|
877
897
|
route_id: '1234',
|
|
878
|
-
direction_id: 1
|
|
898
|
+
direction_id: 1,
|
|
879
899
|
});
|
|
880
900
|
```
|
|
881
901
|
|
|
@@ -891,7 +911,7 @@ getStopAttributes();
|
|
|
891
911
|
|
|
892
912
|
// Get stop attributes for specific stop
|
|
893
913
|
getStopAttributes({
|
|
894
|
-
stop_id: '1234'
|
|
914
|
+
stop_id: '1234',
|
|
895
915
|
});
|
|
896
916
|
```
|
|
897
917
|
|
|
@@ -907,7 +927,7 @@ getTimetables();
|
|
|
907
927
|
|
|
908
928
|
// Get a specific timetable
|
|
909
929
|
getTimetables({
|
|
910
|
-
timetable_id: '1'
|
|
930
|
+
timetable_id: '1',
|
|
911
931
|
});
|
|
912
932
|
```
|
|
913
933
|
|
|
@@ -923,7 +943,7 @@ getTimetableStopOrders();
|
|
|
923
943
|
|
|
924
944
|
// Get timetable_stop_orders for a specific timetable
|
|
925
945
|
getTimetableStopOrders({
|
|
926
|
-
timetable_id: '1'
|
|
946
|
+
timetable_id: '1',
|
|
927
947
|
});
|
|
928
948
|
```
|
|
929
949
|
|
|
@@ -939,7 +959,7 @@ getTimetablePages();
|
|
|
939
959
|
|
|
940
960
|
// Get a specific timetable_page
|
|
941
961
|
getTimetablePages({
|
|
942
|
-
timetable_page_id: '2'
|
|
962
|
+
timetable_page_id: '2',
|
|
943
963
|
});
|
|
944
964
|
```
|
|
945
965
|
|
|
@@ -955,7 +975,7 @@ getTimetableNotes();
|
|
|
955
975
|
|
|
956
976
|
// Get a specific timetable_note
|
|
957
977
|
getTimetableNotes({
|
|
958
|
-
note_id: '1'
|
|
978
|
+
note_id: '1',
|
|
959
979
|
});
|
|
960
980
|
```
|
|
961
981
|
|
|
@@ -971,7 +991,7 @@ getTimetableNotesReferences();
|
|
|
971
991
|
|
|
972
992
|
// Get all timetable_notes_references for a specific timetable
|
|
973
993
|
getTimetableNotesReferences({
|
|
974
|
-
timetable_id: '4'
|
|
994
|
+
timetable_id: '4',
|
|
975
995
|
});
|
|
976
996
|
```
|
|
977
997
|
|
|
@@ -989,7 +1009,6 @@ To run a specific test:
|
|
|
989
1009
|
|
|
990
1010
|
NODE_ENV=test mocha ./test/mocha/gtfs.get-stoptimes.js
|
|
991
1011
|
|
|
992
|
-
|
|
993
1012
|
### Linting
|
|
994
1013
|
|
|
995
1014
|
npm run lint
|