gtfs 3.8.0 → 4.0.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/@types/index.d.ts +35 -60
- package/@types/tests.ts +18 -13
- package/CHANGELOG.md +10 -0
- package/README.md +227 -207
- package/lib/advancedQuery.js +8 -17
- package/lib/db.js +29 -59
- package/lib/export.js +16 -10
- package/lib/gtfs/agencies.js +8 -6
- package/lib/gtfs/areas.js +8 -11
- package/lib/gtfs/attributions.js +8 -6
- package/lib/gtfs/calendar-dates.js +8 -6
- package/lib/gtfs/calendars.js +8 -6
- package/lib/gtfs/fare-attributes.js +8 -6
- package/lib/gtfs/fare-leg-rules.js +8 -6
- package/lib/gtfs/fare-products.js +8 -6
- package/lib/gtfs/fare-rules.js +8 -6
- package/lib/gtfs/fare-transfer-rules.js +8 -6
- package/lib/gtfs/feed-info.js +8 -6
- package/lib/gtfs/frequencies.js +8 -6
- package/lib/gtfs/levels.js +8 -11
- package/lib/gtfs/pathways.js +8 -6
- package/lib/gtfs/routes.js +8 -11
- package/lib/gtfs/shapes.js +34 -39
- package/lib/gtfs/stop-areas.js +8 -6
- package/lib/gtfs/stop-times.js +8 -6
- package/lib/gtfs/stops.js +27 -33
- package/lib/gtfs/transfers.js +8 -6
- package/lib/gtfs/translations.js +8 -6
- package/lib/gtfs/trips.js +8 -11
- package/lib/gtfs-realtime/service-alerts.js +9 -7
- package/lib/gtfs-realtime/stop-times-updates.js +9 -7
- package/lib/gtfs-realtime/trip-updates.js +9 -7
- package/lib/gtfs-realtime/vehicle-positions.js +9 -7
- package/lib/gtfs-ride/board-alights.js +8 -6
- package/lib/gtfs-ride/ride-feed-infos.js +8 -6
- package/lib/gtfs-ride/rider-trips.js +8 -6
- package/lib/gtfs-ride/riderships.js +8 -6
- package/lib/gtfs-ride/trip-capacities.js +8 -6
- package/lib/gtfs.js +3 -9
- package/lib/import.js +195 -202
- package/lib/non-standard/directions.js +8 -6
- package/lib/non-standard/stop-attributes.js +8 -6
- package/lib/non-standard/timetable-notes-references.js +8 -6
- package/lib/non-standard/timetable-notes.js +8 -6
- package/lib/non-standard/timetable-pages.js +8 -6
- package/lib/non-standard/timetable-stop-order.js +8 -6
- package/lib/non-standard/timetables.js +8 -6
- package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
- package/package.json +2 -3
- package/test/mocha/advanced-query.js +9 -15
- package/test/mocha/export-gtfs.js +5 -6
- package/test/mocha/fare-transfer-rules.js +32 -0
- package/test/mocha/get-agencies.js +13 -19
- package/test/mocha/get-areas.js +27 -0
- package/test/mocha/get-attributions.js +7 -13
- package/test/mocha/get-board-alights.js +7 -13
- package/test/mocha/get-calendar-dates.js +11 -17
- package/test/mocha/get-calendars.js +11 -17
- package/test/mocha/get-directions.js +7 -13
- package/test/mocha/get-fare-attributes.js +9 -15
- package/test/mocha/get-fare-leg-rules.js +27 -0
- package/test/mocha/get-fare-products.js +27 -0
- package/test/mocha/get-fare-rules.js +9 -15
- package/test/mocha/get-feed-info.js +7 -13
- package/test/mocha/get-frequencies.js +7 -13
- package/test/mocha/get-levels.js +7 -7
- package/test/mocha/get-pathways.js +7 -13
- package/test/mocha/get-ride-feed-infos.js +7 -13
- package/test/mocha/get-rider-trips.js +7 -13
- package/test/mocha/get-riderships.js +7 -13
- package/test/mocha/get-routes.js +13 -13
- package/test/mocha/get-shapes-as-geojson.js +14 -15
- package/test/mocha/get-shapes.js +25 -25
- package/test/mocha/get-stop-attributes.js +7 -13
- package/test/mocha/get-stops-as-geojson.js +13 -19
- package/test/mocha/get-stops.js +19 -19
- package/test/mocha/get-stoptimes.js +11 -17
- package/test/mocha/get-timetable-pages.js +7 -13
- package/test/mocha/get-timetable-stop-orders.js +6 -7
- package/test/mocha/get-timetables.js +7 -13
- package/test/mocha/get-transfers.js +7 -13
- package/test/mocha/get-translations.js +7 -13
- package/test/mocha/get-trip-capacities.js +7 -13
- package/test/mocha/get-trips.js +9 -9
- package/test/mocha/import-gtfs.js +11 -11
- package/test/mocha/{get-db.js → open-db.js} +37 -29
- package/test/mocha/raw-query.js +34 -0
- package/test/mocha/exec-raw-query.js +0 -39
- package/test/mocha/run-raw-query.js +0 -54
package/README.md
CHANGED
|
@@ -29,13 +29,35 @@ You can use it as a [command-line tool](#command-line-examples) or as a [node.js
|
|
|
29
29
|
|
|
30
30
|
This library has four parts: the [GTFS import script](#gtfs-import-script), [GTFS export script](#gtfs-export-script) and [GTFS-Realtime update script](#gtfsrealtime-update-script) and the [query methods](#query-methods)
|
|
31
31
|
|
|
32
|
+
## Breaking changes in Version 4
|
|
33
|
+
|
|
34
|
+
Version 4 of node-gtfs switched to using the better-sqlite3 library. This allowed all query methods to become synchronous and speeds up import and export.
|
|
35
|
+
|
|
36
|
+
- All query methods are now synchronous.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
// Version 3
|
|
40
|
+
const routes = await getRoutes();
|
|
41
|
+
|
|
42
|
+
// Version 4
|
|
43
|
+
const routes = getRoutes();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `runRawQuery` has been removed. Use [Raw SQLite Query](#raw-sqlite-query) instead.
|
|
47
|
+
- `execRawQuery` has been removed. Use [Raw SQLite Query](#raw-sqlite-query) instead.
|
|
48
|
+
- `getDb` has been removed. Use `openDb` instead.
|
|
49
|
+
|
|
32
50
|
## Installation
|
|
33
51
|
|
|
34
|
-
|
|
52
|
+
To use this library as a command-line utility, install it globally [npm](https://npmjs.org):
|
|
35
53
|
|
|
36
54
|
npm install gtfs -g
|
|
37
55
|
|
|
38
|
-
|
|
56
|
+
This will add the `gtfs-import` and `gtfs-export` scripts to your path.
|
|
57
|
+
|
|
58
|
+
If you are using this as a node module as part of an application, include it in your project's `package.json` file.
|
|
59
|
+
|
|
60
|
+
npm install gtfs
|
|
39
61
|
|
|
40
62
|
## Quick Start
|
|
41
63
|
|
|
@@ -471,11 +493,13 @@ await exportGtfs(config);
|
|
|
471
493
|
|
|
472
494
|
## Query Methods
|
|
473
495
|
|
|
474
|
-
This library includes many methods you can use in your project to query GTFS data.
|
|
496
|
+
This library includes many methods you can use in your project to query GTFS data.
|
|
497
|
+
|
|
498
|
+
Most methods accept three optional arguments: `query`, `fields`, `sortBy` and `options`.
|
|
475
499
|
|
|
476
|
-
|
|
500
|
+
For more advanced queries, you can use `advancedQuery` or any query method from [better-sqlite3](#raw-sqlite-query).
|
|
477
501
|
|
|
478
|
-
|
|
502
|
+
You need to run `openDb(config)` before using any query methods.
|
|
479
503
|
|
|
480
504
|
#### Query
|
|
481
505
|
|
|
@@ -488,11 +512,12 @@ const config = JSON.parse(
|
|
|
488
512
|
await readFile(new URL('./config.json', import.meta.url))
|
|
489
513
|
);
|
|
490
514
|
|
|
491
|
-
const db =
|
|
492
|
-
const routes =
|
|
493
|
-
{},
|
|
494
|
-
['route_id', 'route_short_name', 'route_color'],
|
|
495
|
-
[['route_short_name', 'ASC']]
|
|
515
|
+
const db = openDb(config);
|
|
516
|
+
const routes = getRoutes(
|
|
517
|
+
{}, // No query filters
|
|
518
|
+
['route_id', 'route_short_name', 'route_color'], // Only return these fields
|
|
519
|
+
[['route_short_name', 'ASC']], // Sort by this field and direction
|
|
520
|
+
{ db: db } // Options for the query. Can specify which database to use if more than one are open
|
|
496
521
|
);
|
|
497
522
|
```
|
|
498
523
|
|
|
@@ -505,8 +530,8 @@ const config = JSON.parse(
|
|
|
505
530
|
await readFile(new URL('./config.json', import.meta.url))
|
|
506
531
|
);
|
|
507
532
|
|
|
508
|
-
const db =
|
|
509
|
-
const trips =
|
|
533
|
+
const db = openDb(config);
|
|
534
|
+
const trips = getTrips(
|
|
510
535
|
{
|
|
511
536
|
route_id: '123',
|
|
512
537
|
},
|
|
@@ -521,8 +546,8 @@ import { openDb, getStops } from 'gtfs';
|
|
|
521
546
|
import { readFile } from 'fs/promises';
|
|
522
547
|
const config = JSON.parse(await readFile(new URL('./config.json', import.meta.url)));
|
|
523
548
|
|
|
524
|
-
const db =
|
|
525
|
-
const stops =
|
|
549
|
+
const db = openDb(config);
|
|
550
|
+
const stops = getStops(
|
|
526
551
|
{
|
|
527
552
|
stop_id: [
|
|
528
553
|
'123',
|
|
@@ -544,80 +569,77 @@ import { openDb } from 'gtfs';
|
|
|
544
569
|
Open database before making any queries
|
|
545
570
|
|
|
546
571
|
```js
|
|
547
|
-
const db =
|
|
572
|
+
const db = openDb(config);
|
|
548
573
|
```
|
|
549
574
|
|
|
550
|
-
### getAgencies(query, fields, sortBy)
|
|
575
|
+
### getAgencies(query, fields, sortBy, options)
|
|
551
576
|
|
|
552
|
-
|
|
577
|
+
Returns an array of agencies that match query parameters. [Details on agency.txt](https://gtfs.org/schedule/reference/#agencytxt)
|
|
553
578
|
|
|
554
579
|
```js
|
|
555
580
|
import { getAgencies } from 'gtfs';
|
|
556
581
|
|
|
557
582
|
// Get all agencies
|
|
558
|
-
const agencies =
|
|
583
|
+
const agencies = getAgencies();
|
|
559
584
|
|
|
560
585
|
// Get a specific agency
|
|
561
|
-
const agencies =
|
|
586
|
+
const agencies = getAgencies({
|
|
562
587
|
agency_id: 'caltrain',
|
|
563
588
|
});
|
|
564
589
|
```
|
|
565
590
|
|
|
566
|
-
### getAreas(query, fields, sortBy)
|
|
591
|
+
### getAreas(query, fields, sortBy, options)
|
|
567
592
|
|
|
568
|
-
|
|
593
|
+
Returns an array of areas that match query parameters. [Details on areas.txt](https://gtfs.org/schedule/reference/#areastxt)
|
|
569
594
|
|
|
570
595
|
```js
|
|
571
596
|
import { getAreas } from 'gtfs';
|
|
572
597
|
|
|
573
598
|
// Get all areas
|
|
574
|
-
const areas =
|
|
599
|
+
const areas = getAreas();
|
|
575
600
|
|
|
576
601
|
// Get a specific area
|
|
577
|
-
const areas =
|
|
602
|
+
const areas = getAreas({
|
|
578
603
|
area_id: 'area1',
|
|
579
604
|
});
|
|
580
605
|
```
|
|
581
606
|
|
|
582
|
-
### getAttributions(query, fields, sortBy)
|
|
607
|
+
### getAttributions(query, fields, sortBy, options)
|
|
583
608
|
|
|
584
|
-
|
|
609
|
+
Returns an array of attributions that match query parameters. [Details on attributions.txt](https://gtfs.org/schedule/reference/#attributionstxt)
|
|
585
610
|
|
|
586
611
|
```js
|
|
587
612
|
import { getAttributions } from 'gtfs';
|
|
588
613
|
|
|
589
614
|
// Get all attributions
|
|
590
|
-
const attributions =
|
|
615
|
+
const attributions = getAttributions();
|
|
591
616
|
|
|
592
617
|
// Get a specific attribution
|
|
593
|
-
const attributions =
|
|
618
|
+
const attributions = getAttributions({
|
|
594
619
|
attribution_id: '123',
|
|
595
620
|
});
|
|
596
621
|
```
|
|
597
622
|
|
|
598
|
-
### getRoutes(query, fields, sortBy)
|
|
623
|
+
### getRoutes(query, fields, sortBy, options)
|
|
599
624
|
|
|
600
|
-
|
|
625
|
+
Returns an array of routes that match query parameters. [Details on routes.txt](https://gtfs.org/schedule/reference/#routestxt)
|
|
601
626
|
|
|
602
627
|
```js
|
|
603
628
|
import { getRoutes } from 'gtfs';
|
|
604
629
|
|
|
605
630
|
// Get all routes, sorted by route_short_name
|
|
606
|
-
const routes =
|
|
631
|
+
const routes = getRoutes({}, [], [['route_short_name', 'ASC']]);
|
|
607
632
|
|
|
608
633
|
// Get a specific route
|
|
609
|
-
const routes =
|
|
634
|
+
const routes = getRoutes({
|
|
610
635
|
route_id: 'Lo-16APR',
|
|
611
636
|
});
|
|
612
|
-
```
|
|
613
637
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// Get routes that serve a specific stop, sorted by `stop_name`.
|
|
620
|
-
const routes = await getRoutes(
|
|
638
|
+
/*
|
|
639
|
+
* `getRoutes` allows passing a `stop_id` as part of the query. This will
|
|
640
|
+
* query stoptimes and trips to find all routes that serve that `stop_id`.
|
|
641
|
+
*/
|
|
642
|
+
const routes = getRoutes(
|
|
621
643
|
{
|
|
622
644
|
stop_id: '70011',
|
|
623
645
|
},
|
|
@@ -626,18 +648,18 @@ const routes = await getRoutes(
|
|
|
626
648
|
);
|
|
627
649
|
```
|
|
628
650
|
|
|
629
|
-
### getStops(query, fields, sortBy)
|
|
651
|
+
### getStops(query, fields, sortBy, options)
|
|
630
652
|
|
|
631
|
-
|
|
653
|
+
Returns an array of stops that match query parameters. [Details on stops.txt](https://gtfs.org/schedule/reference/#stopstxt)
|
|
632
654
|
|
|
633
655
|
```js
|
|
634
656
|
import { getStops } from 'gtfs';
|
|
635
657
|
|
|
636
658
|
// Get all stops
|
|
637
|
-
const stops =
|
|
659
|
+
const stops = getStops();
|
|
638
660
|
|
|
639
661
|
// Get a specific stop by stop_id
|
|
640
|
-
const stops =
|
|
662
|
+
const stops = getStops({
|
|
641
663
|
stop_id: '70011',
|
|
642
664
|
});
|
|
643
665
|
|
|
@@ -645,7 +667,7 @@ const stops = await getStops({
|
|
|
645
667
|
* `getStops` allows passing a `route_id` in the query and it will
|
|
646
668
|
* query trips and stoptimes to find all stops served by that `route_id`.
|
|
647
669
|
*/
|
|
648
|
-
const stops =
|
|
670
|
+
const stops = getStops({
|
|
649
671
|
route_id: 'Lo-16APR',
|
|
650
672
|
});
|
|
651
673
|
|
|
@@ -653,7 +675,7 @@ const stops = await getStops({
|
|
|
653
675
|
* `getStops` allows passing a `trip_id` in the query and it will query
|
|
654
676
|
* stoptimes to find all stops on that `trip_id`.
|
|
655
677
|
*/
|
|
656
|
-
const stops =
|
|
678
|
+
const stops = getStops({
|
|
657
679
|
trip_id: '37a',
|
|
658
680
|
});
|
|
659
681
|
|
|
@@ -661,44 +683,44 @@ const stops = await getStops({
|
|
|
661
683
|
* `getStops` allows passing a `shape_id` in the query and it will query
|
|
662
684
|
* trips and stoptimes to find all stops that use that `shape_id`.
|
|
663
685
|
*/
|
|
664
|
-
const stops =
|
|
686
|
+
const stops = getStops({
|
|
665
687
|
shape_id: 'cal_sf_tam',
|
|
666
688
|
});
|
|
667
689
|
```
|
|
668
690
|
|
|
669
691
|
### getStopsAsGeoJSON(query)
|
|
670
692
|
|
|
671
|
-
|
|
693
|
+
Returns geoJSON object of stops that match query parameters. All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.
|
|
672
694
|
|
|
673
695
|
```js
|
|
674
696
|
import { getStopsAsGeoJSON } from 'gtfs';
|
|
675
697
|
|
|
676
698
|
// Get all stops for an agency as geoJSON
|
|
677
|
-
const stopsGeojson =
|
|
699
|
+
const stopsGeojson = getStopsAsGeoJSON();
|
|
678
700
|
|
|
679
701
|
// Get all stops for a specific route as geoJSON
|
|
680
|
-
const stopsGeojson =
|
|
702
|
+
const stopsGeojson = getStopsAsGeoJSON({
|
|
681
703
|
route_id: 'Lo-16APR',
|
|
682
704
|
});
|
|
683
705
|
```
|
|
684
706
|
|
|
685
|
-
### getStoptimes(query, fields, sortBy)
|
|
707
|
+
### getStoptimes(query, fields, sortBy, options)
|
|
686
708
|
|
|
687
|
-
|
|
709
|
+
Returns an array of stop_times that match query parameters. [Details on stop_times.txt](https://gtfs.org/schedule/reference/#stop_timestxt)
|
|
688
710
|
|
|
689
711
|
```js
|
|
690
712
|
import { getStoptimes } from 'gtfs';
|
|
691
713
|
|
|
692
714
|
// Get all stoptimes
|
|
693
|
-
const stoptimes =
|
|
715
|
+
const stoptimes = getStoptimes();
|
|
694
716
|
|
|
695
717
|
// Get all stoptimes for a specific stop
|
|
696
|
-
const stoptimes =
|
|
718
|
+
const stoptimes = getStoptimes({
|
|
697
719
|
stop_id: '70011',
|
|
698
720
|
});
|
|
699
721
|
|
|
700
722
|
// Get all stoptimes for a specific trip, sorted by stop_sequence
|
|
701
|
-
const stoptimes =
|
|
723
|
+
const stoptimes = getStoptimes(
|
|
702
724
|
{
|
|
703
725
|
trip_id: '37a',
|
|
704
726
|
},
|
|
@@ -707,60 +729,57 @@ const stoptimes = await getStoptimes(
|
|
|
707
729
|
);
|
|
708
730
|
|
|
709
731
|
// Get all stoptimes for a specific stop and service_id
|
|
710
|
-
const stoptimes =
|
|
732
|
+
const stoptimes = getStoptimes({
|
|
711
733
|
stop_id: '70011',
|
|
712
734
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
713
735
|
});
|
|
714
736
|
```
|
|
715
737
|
|
|
716
|
-
### getTrips(query, fields, sortBy)
|
|
738
|
+
### getTrips(query, fields, sortBy, options)
|
|
717
739
|
|
|
718
|
-
|
|
740
|
+
Returns an array of trips that match query parameters. [Details on trips.txt](https://gtfs.org/schedule/reference/#tripstxt)
|
|
719
741
|
|
|
720
742
|
```js
|
|
721
743
|
import { getTrips } from 'gtfs';
|
|
722
744
|
|
|
723
745
|
// Get all trips
|
|
724
|
-
const trips =
|
|
746
|
+
const trips = getTrips();
|
|
725
747
|
|
|
726
748
|
// Get trips for a specific route and direction
|
|
727
|
-
const trips =
|
|
749
|
+
const trips = getTrips({
|
|
728
750
|
route_id: 'Lo-16APR',
|
|
729
751
|
direction_id: 0
|
|
730
752
|
});
|
|
731
753
|
|
|
732
754
|
// Get trips for direction '' or null
|
|
733
|
-
const trips =
|
|
755
|
+
const trips = getTrips({
|
|
734
756
|
route_id: 'Lo-16APR',
|
|
735
757
|
direction_id: null
|
|
736
758
|
});
|
|
737
759
|
|
|
738
760
|
// Get trips for a specific route and direction limited by a service_id
|
|
739
|
-
const trips =
|
|
761
|
+
const trips = getTrips({
|
|
740
762
|
route_id: 'Lo-16APR',
|
|
741
763
|
direction_id: 0,
|
|
742
764
|
service_id: '
|
|
743
765
|
});
|
|
744
766
|
```
|
|
745
767
|
|
|
746
|
-
### getShapes(query, fields, sortBy)
|
|
768
|
+
### getShapes(query, fields, sortBy, options)
|
|
747
769
|
|
|
748
|
-
|
|
770
|
+
Returns an array of shapes that match query parameters. [Details on shapes.txt](https://gtfs.org/schedule/reference/#shapestxt)
|
|
749
771
|
|
|
750
772
|
```js
|
|
751
773
|
import { getShapes } from 'gtfs';
|
|
752
774
|
|
|
753
775
|
// Get all shapes for an agency
|
|
754
|
-
const shapes =
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
`getShapes` allows passing a `route_id` in the query and it will query trips to find all shapes served by that `route_id`.
|
|
758
|
-
|
|
759
|
-
```js
|
|
760
|
-
import { getShapes } from 'gtfs';
|
|
776
|
+
const shapes = getShapes();
|
|
761
777
|
|
|
762
|
-
|
|
763
|
-
|
|
778
|
+
/*
|
|
779
|
+
* `getShapes` allows passing a `route_id` in the query and it will query
|
|
780
|
+
* trips to find all shapes served by that `route_id`.
|
|
781
|
+
*/
|
|
782
|
+
const shapes = getShapes({
|
|
764
783
|
route_id: 'Lo-16APR',
|
|
765
784
|
});
|
|
766
785
|
|
|
@@ -768,7 +787,7 @@ const shapes = await getShapes({
|
|
|
768
787
|
* `getShapes` allows passing a `trip_id` in the query and it will query
|
|
769
788
|
* trips to find all shapes served by that `trip_id`.
|
|
770
789
|
*/
|
|
771
|
-
const shapes =
|
|
790
|
+
const shapes = getShapes({
|
|
772
791
|
trip_id: '37a',
|
|
773
792
|
});
|
|
774
793
|
|
|
@@ -776,427 +795,422 @@ const shapes = await getShapes({
|
|
|
776
795
|
* `getShapes` allows passing a `service_id` in the query and it will query
|
|
777
796
|
* trips to find all shapes served by that `service_id`.
|
|
778
797
|
*/
|
|
779
|
-
const shapes =
|
|
798
|
+
const shapes = getShapes({
|
|
780
799
|
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
781
800
|
});
|
|
782
801
|
```
|
|
783
802
|
|
|
784
803
|
### getShapesAsGeoJSON(query)
|
|
785
804
|
|
|
786
|
-
|
|
805
|
+
Returns a geoJSON object of shapes that match query parameters. All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.
|
|
787
806
|
|
|
788
807
|
```js
|
|
789
808
|
import { getShapesAsGeoJSON } from 'gtfs';
|
|
790
809
|
|
|
791
810
|
// Get geoJSON of all routes in an agency
|
|
792
|
-
const shapesGeojson =
|
|
811
|
+
const shapesGeojson = getShapesAsGeoJSON();
|
|
793
812
|
|
|
794
813
|
// Get geoJSON of shapes for a specific route
|
|
795
|
-
const shapesGeojson =
|
|
814
|
+
const shapesGeojson = getShapesAsGeoJSON({
|
|
796
815
|
route_id: 'Lo-16APR',
|
|
797
816
|
});
|
|
798
817
|
|
|
799
818
|
// Get geoJSON of shapes for a specific trip
|
|
800
|
-
const shapesGeojson =
|
|
819
|
+
const shapesGeojson = getShapesAsGeoJSON({
|
|
801
820
|
trip_id: '37a',
|
|
802
821
|
});
|
|
803
822
|
|
|
804
823
|
// Get geoJSON of shapes for a specific `service_id`
|
|
805
|
-
const shapesGeojson =
|
|
824
|
+
const shapesGeojson = getShapesAsGeoJSON({
|
|
806
825
|
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
807
826
|
});
|
|
808
827
|
|
|
809
828
|
// Get geoJSON of shapes for a specific `shape_id`
|
|
810
|
-
const shapesGeojson =
|
|
829
|
+
const shapesGeojson = getShapesAsGeoJSON({
|
|
811
830
|
shape_id: 'cal_sf_tam',
|
|
812
831
|
});
|
|
813
832
|
```
|
|
814
833
|
|
|
815
|
-
### getCalendars(query, fields, sortBy)
|
|
834
|
+
### getCalendars(query, fields, sortBy, options)
|
|
816
835
|
|
|
817
|
-
|
|
836
|
+
Returns an array of calendars that match query parameters. [Details on calendar.txt](https://gtfs.org/schedule/reference/#calendartxt)
|
|
818
837
|
|
|
819
838
|
```js
|
|
820
839
|
import { getCalendars } from 'gtfs';
|
|
821
840
|
|
|
822
841
|
// Get all calendars for an agency
|
|
823
|
-
const calendars =
|
|
842
|
+
const calendars = getCalendars();
|
|
824
843
|
|
|
825
844
|
// Get calendars for a specific `service_id`
|
|
826
|
-
const calendars =
|
|
845
|
+
const calendars = getCalendars({
|
|
827
846
|
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
828
847
|
});
|
|
829
848
|
```
|
|
830
849
|
|
|
831
|
-
### getCalendarDates(query, fields, sortBy)
|
|
850
|
+
### getCalendarDates(query, fields, sortBy, options)
|
|
832
851
|
|
|
833
|
-
|
|
852
|
+
Returns an array of calendar_dates that match query parameters. [Details on calendar_dates.txt](https://gtfs.org/schedule/reference/#calendar_datestxt)
|
|
834
853
|
|
|
835
854
|
```js
|
|
836
855
|
import { getCalendarDates } from 'gtfs';
|
|
837
856
|
|
|
838
857
|
// Get all calendar_dates for an agency
|
|
839
|
-
const calendarDates =
|
|
858
|
+
const calendarDates = getCalendarDates();
|
|
840
859
|
|
|
841
860
|
// Get calendar_dates for a specific `service_id`
|
|
842
|
-
const calendarDates =
|
|
861
|
+
const calendarDates = getCalendarDates({
|
|
843
862
|
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
844
863
|
});
|
|
845
864
|
```
|
|
846
865
|
|
|
847
|
-
### getFareAttributes(query, fields, sortBy)
|
|
866
|
+
### getFareAttributes(query, fields, sortBy, options)
|
|
848
867
|
|
|
849
|
-
|
|
868
|
+
Returns an array of fare_attributes that match query parameters. [Details on fare_attributes.txt](https://gtfs.org/schedule/reference/#fare_attributestxt)
|
|
850
869
|
|
|
851
870
|
```js
|
|
852
871
|
import { getFareAttributes } from 'gtfs';
|
|
853
872
|
|
|
854
873
|
// Get all `fare_attributes` for an agency
|
|
855
|
-
const fareAttributes =
|
|
874
|
+
const fareAttributes = getFareAttributes();
|
|
856
875
|
|
|
857
876
|
// Get `fare_attributes` for a specific `fare_id`
|
|
858
|
-
const fareAttributes =
|
|
877
|
+
const fareAttributes = getFareAttributes({
|
|
859
878
|
fare_id: '123',
|
|
860
879
|
});
|
|
861
880
|
```
|
|
862
881
|
|
|
863
|
-
### getFareLegRules(query, fields, sortBy)
|
|
882
|
+
### getFareLegRules(query, fields, sortBy, options)
|
|
864
883
|
|
|
865
|
-
|
|
884
|
+
Returns an array of fare_leg_rules that match query parameters. [Details on fare_leg_rules.txt](https://gtfs.org/schedule/reference/#fare_leg_rulestxt)
|
|
866
885
|
|
|
867
886
|
```js
|
|
868
887
|
import { getFareLegRules } from 'gtfs';
|
|
869
888
|
|
|
870
889
|
// Get all fare leg rules
|
|
871
|
-
const fareLegRules =
|
|
890
|
+
const fareLegRules = getFareLegRules();
|
|
872
891
|
|
|
873
892
|
// Get fare leg rules for a specific fare product
|
|
874
|
-
const fareLegRules =
|
|
893
|
+
const fareLegRules = getFareLegRules({
|
|
875
894
|
fare_product_id: 'product1',
|
|
876
895
|
});
|
|
877
896
|
```
|
|
878
897
|
|
|
879
|
-
### getFareProducts(query, fields, sortBy)
|
|
898
|
+
### getFareProducts(query, fields, sortBy, options)
|
|
880
899
|
|
|
881
|
-
|
|
900
|
+
Returns an array of fare_products that match query parameters. [Details on fare_products.txt](https://gtfs.org/schedule/reference/#fare_productstxt)
|
|
882
901
|
|
|
883
902
|
```js
|
|
884
903
|
import { getFareProducts } from 'gtfs';
|
|
885
904
|
|
|
886
905
|
// Get all fare products
|
|
887
|
-
const fareProducts =
|
|
906
|
+
const fareProducts = getFareProducts();
|
|
888
907
|
|
|
889
908
|
// Get a specific fare product
|
|
890
|
-
const fareProducts =
|
|
909
|
+
const fareProducts = getFareProducts({
|
|
891
910
|
fare_product_id: 'product1',
|
|
892
911
|
});
|
|
893
912
|
```
|
|
894
913
|
|
|
895
|
-
### getFareRules(query, fields, sortBy)
|
|
914
|
+
### getFareRules(query, fields, sortBy, options)
|
|
896
915
|
|
|
897
|
-
|
|
916
|
+
Returns an array of fare_rules that match query parameters. [Details on fare_rules.txt](https://gtfs.org/schedule/reference/#fare_rulestxt)
|
|
898
917
|
|
|
899
918
|
```js
|
|
900
919
|
import { getFareRules } from 'gtfs';
|
|
901
920
|
|
|
902
921
|
// Get all `fare_rules` for an agency
|
|
903
|
-
const fareRules =
|
|
922
|
+
const fareRules = getFareRules();
|
|
904
923
|
|
|
905
924
|
// Get fare_rules for a specific route
|
|
906
|
-
const fareRules =
|
|
925
|
+
const fareRules = getFareRules({
|
|
907
926
|
route_id: 'Lo-16APR',
|
|
908
927
|
});
|
|
909
928
|
```
|
|
910
929
|
|
|
911
|
-
### getFareTransferRules(query, fields, sortBy)
|
|
930
|
+
### getFareTransferRules(query, fields, sortBy, options)
|
|
912
931
|
|
|
913
|
-
|
|
932
|
+
Returns an array of fare_transfer_rules that match query parameters. [Details on fare_transfer_rules.txt](https://gtfs.org/schedule/reference/#fare_transfer_rulestxt)
|
|
914
933
|
|
|
915
934
|
```js
|
|
916
935
|
import { getFareTransferRules } from 'gtfs';
|
|
917
936
|
|
|
918
937
|
// Get all fare transfer rules
|
|
919
|
-
const fareTransferRules =
|
|
938
|
+
const fareTransferRules = getFareTransferRules();
|
|
920
939
|
|
|
921
940
|
// Get a all fare transfer rules for a specific fare product
|
|
922
|
-
const fareTransferRules =
|
|
941
|
+
const fareTransferRules = getFareTransferRules({
|
|
923
942
|
fare_product_id: 'product1',
|
|
924
943
|
});
|
|
925
944
|
```
|
|
926
945
|
|
|
927
|
-
### getFeedInfo(query, fields, sortBy)
|
|
946
|
+
### getFeedInfo(query, fields, sortBy, options)
|
|
928
947
|
|
|
929
|
-
|
|
948
|
+
Returns an array of feed_info that match query parameters. [Details on feed_info.txt](https://gtfs.org/schedule/reference/#feed_infotxt)
|
|
930
949
|
|
|
931
950
|
```js
|
|
932
951
|
import { getFeedInfo } from 'gtfs';
|
|
933
952
|
|
|
934
953
|
// Get feed_info
|
|
935
|
-
const feedInfo =
|
|
954
|
+
const feedInfo = getFeedInfo();
|
|
936
955
|
```
|
|
937
956
|
|
|
938
|
-
### getFrequencies(query, fields, sortBy)
|
|
957
|
+
### getFrequencies(query, fields, sortBy, options)
|
|
939
958
|
|
|
940
|
-
|
|
959
|
+
Returns an array of frequencies that match query parameters. [Details on frequencies.txt](https://gtfs.org/schedule/reference/#frequenciestxt)
|
|
941
960
|
|
|
942
961
|
```js
|
|
943
962
|
import { getFrequencies } from 'gtfs';
|
|
944
963
|
|
|
945
964
|
// Get all frequencies
|
|
946
|
-
const frequencies =
|
|
965
|
+
const frequencies = getFrequencies();
|
|
947
966
|
|
|
948
967
|
// Get frequencies for a specific trip
|
|
949
|
-
const frequencies =
|
|
968
|
+
const frequencies = getFrequencies({
|
|
950
969
|
trip_id: '1234',
|
|
951
970
|
});
|
|
952
971
|
```
|
|
953
972
|
|
|
954
|
-
### getLevels(query, fields, sortBy)
|
|
973
|
+
### getLevels(query, fields, sortBy, options)
|
|
955
974
|
|
|
956
|
-
|
|
975
|
+
Returns an array of levels that match query parameters. [Details on levels.txt](https://gtfs.org/schedule/reference/#levelstxt)
|
|
957
976
|
|
|
958
977
|
```js
|
|
959
978
|
import { getLevels } from 'gtfs';
|
|
960
979
|
|
|
961
980
|
// Get all levels
|
|
962
|
-
const levels =
|
|
981
|
+
const levels = getLevels();
|
|
963
982
|
```
|
|
964
983
|
|
|
965
|
-
### getPathways(query, fields, sortBy)
|
|
984
|
+
### getPathways(query, fields, sortBy, options)
|
|
966
985
|
|
|
967
|
-
|
|
986
|
+
Returns an array of pathways that match query parameters. [Details on pathways.txt](https://gtfs.org/schedule/reference/#pathwaystxt)
|
|
968
987
|
|
|
969
988
|
```js
|
|
970
989
|
import { getPathways } from 'gtfs';
|
|
971
990
|
|
|
972
991
|
// Get all pathways
|
|
973
|
-
const pathways =
|
|
992
|
+
const pathways = getPathways();
|
|
974
993
|
```
|
|
975
994
|
|
|
976
|
-
### getTransfers(query, fields, sortBy)
|
|
995
|
+
### getTransfers(query, fields, sortBy, options)
|
|
977
996
|
|
|
978
|
-
|
|
997
|
+
Returns an array of transfers that match query parameters. [Details on transfers.txt](https://gtfs.org/schedule/reference/#transferstxt)
|
|
979
998
|
|
|
980
999
|
```js
|
|
981
1000
|
import { getTransfers } from 'gtfs';
|
|
982
1001
|
|
|
983
1002
|
// Get all transfers
|
|
984
|
-
const transfers =
|
|
1003
|
+
const transfers = getTransfers();
|
|
985
1004
|
|
|
986
1005
|
// Get transfers for a specific stop
|
|
987
|
-
const transfers =
|
|
1006
|
+
const transfers = getTransfers({
|
|
988
1007
|
from_stop_id: '1234',
|
|
989
1008
|
});
|
|
990
1009
|
```
|
|
991
1010
|
|
|
992
|
-
### getTranslations(query, fields, sortBy)
|
|
1011
|
+
### getTranslations(query, fields, sortBy, options)
|
|
993
1012
|
|
|
994
|
-
|
|
1013
|
+
Returns an array of translations that match query parameters. [Details on translations.txt](https://gtfs.org/schedule/reference/#translationstxt)
|
|
995
1014
|
|
|
996
1015
|
```js
|
|
997
1016
|
import { getTranslations } from 'gtfs';
|
|
998
1017
|
|
|
999
1018
|
// Get all translations
|
|
1000
|
-
const translations =
|
|
1019
|
+
const translations = getTranslations();
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
### getStopAreas(query, fields, sortBy, options)
|
|
1023
|
+
|
|
1024
|
+
Returns an array of stop_areas that match query parameters. [Details on stop_areas.txt](https://gtfs.org/schedule/reference/#stop_areastxt)
|
|
1025
|
+
|
|
1026
|
+
```js
|
|
1027
|
+
import { getStopAreas } from 'gtfs';
|
|
1028
|
+
|
|
1029
|
+
// Get all stop areas
|
|
1030
|
+
const stopAreas = getStopAreas();
|
|
1001
1031
|
```
|
|
1002
1032
|
|
|
1003
|
-
### getDirections(query, fields, sortBy)
|
|
1033
|
+
### getDirections(query, fields, sortBy, options)
|
|
1004
1034
|
|
|
1005
|
-
|
|
1035
|
+
Returns an array of directions that match query parameters. This is for the non-standard `directions.txt` file. [Details on directions.txt](https://trilliumtransit.com/gtfs/reference/#directions)
|
|
1006
1036
|
|
|
1007
1037
|
```js
|
|
1008
1038
|
import { getDirections } from 'gtfs';
|
|
1009
1039
|
|
|
1010
1040
|
// Get all directions
|
|
1011
|
-
const directions =
|
|
1041
|
+
const directions = getDirections();
|
|
1012
1042
|
|
|
1013
1043
|
// Get directions for a specific route
|
|
1014
|
-
const directions =
|
|
1044
|
+
const directions = getDirections({
|
|
1015
1045
|
route_id: '1234',
|
|
1016
1046
|
});
|
|
1017
1047
|
|
|
1018
1048
|
// Get directions for a specific route and direction
|
|
1019
|
-
const directions =
|
|
1049
|
+
const directions = getDirections({
|
|
1020
1050
|
route_id: '1234',
|
|
1021
1051
|
direction_id: 1,
|
|
1022
1052
|
});
|
|
1023
1053
|
```
|
|
1024
1054
|
|
|
1025
|
-
###
|
|
1026
|
-
|
|
1027
|
-
Queries stop areas and returns a promise. The result of the promise is an array of stop areas.
|
|
1028
|
-
|
|
1029
|
-
```js
|
|
1030
|
-
import { getStopAreas } from 'gtfs';
|
|
1031
|
-
|
|
1032
|
-
// Get all stop areas
|
|
1033
|
-
const stopAreas = await getStopAreas();
|
|
1034
|
-
```
|
|
1035
|
-
|
|
1036
|
-
### getStopAttributes(query, fields, sortBy)
|
|
1055
|
+
### getStopAttributes(query, fields, sortBy, options)
|
|
1037
1056
|
|
|
1038
|
-
|
|
1057
|
+
Returns an array of stop_attributes that match query parameters. This is for the non-standard `stop_attributes.txt` file. [Details on stop_attributes.txt](https://trilliumtransit.com/gtfs/reference/#stop_attributes)
|
|
1039
1058
|
|
|
1040
1059
|
```js
|
|
1041
1060
|
import { getStopAttributes } from 'gtfs';
|
|
1042
1061
|
|
|
1043
1062
|
// Get all stop attributes
|
|
1044
|
-
const stopAttributes =
|
|
1063
|
+
const stopAttributes = getStopAttributes();
|
|
1045
1064
|
|
|
1046
1065
|
// Get stop attributes for specific stop
|
|
1047
|
-
const stopAttributes =
|
|
1066
|
+
const stopAttributes = getStopAttributes({
|
|
1048
1067
|
stop_id: '1234',
|
|
1049
1068
|
});
|
|
1050
1069
|
```
|
|
1051
1070
|
|
|
1052
|
-
### getTimetables(query, fields, sortBy)
|
|
1071
|
+
### getTimetables(query, fields, sortBy, options)
|
|
1053
1072
|
|
|
1054
|
-
|
|
1073
|
+
Returns an array of timetables that match query parameters. This is for the non-standard `timetables.txt` file used in GTFS-to-HTML. [Details on timetables.txt](https://gtfstohtml.com/docs/timetables)
|
|
1055
1074
|
|
|
1056
1075
|
```js
|
|
1057
1076
|
import { getTimetables } from 'gtfs';
|
|
1058
1077
|
|
|
1059
1078
|
// Get all timetables for an agency
|
|
1060
|
-
const timetables =
|
|
1079
|
+
const timetables = getTimetables();
|
|
1061
1080
|
|
|
1062
1081
|
// Get a specific timetable
|
|
1063
|
-
const timetables =
|
|
1082
|
+
const timetables = getTimetables({
|
|
1064
1083
|
timetable_id: '1',
|
|
1065
1084
|
});
|
|
1066
1085
|
```
|
|
1067
1086
|
|
|
1068
|
-
### getTimetableStopOrders(query, fields, sortBy)
|
|
1087
|
+
### getTimetableStopOrders(query, fields, sortBy, options)
|
|
1069
1088
|
|
|
1070
|
-
|
|
1089
|
+
Returns an array of timetable_stop_orders that match query parameters. This is for the non-standard `timetable_stop_order.txt` file used in GTFS-to-HTML. [Details on timetable_stop_order.txt](https://gtfstohtml.com/docs/timetable-stop-order)
|
|
1071
1090
|
|
|
1072
1091
|
```js
|
|
1073
1092
|
import { getTimetableStopOrders } from 'gtfs';
|
|
1074
1093
|
|
|
1075
1094
|
// Get all timetable_stop_orders
|
|
1076
|
-
const timetableStopOrders =
|
|
1095
|
+
const timetableStopOrders = getTimetableStopOrders();
|
|
1077
1096
|
|
|
1078
1097
|
// Get timetable_stop_orders for a specific timetable
|
|
1079
|
-
const timetableStopOrders =
|
|
1098
|
+
const timetableStopOrders = getTimetableStopOrders({
|
|
1080
1099
|
timetable_id: '1',
|
|
1081
1100
|
});
|
|
1082
1101
|
```
|
|
1083
1102
|
|
|
1084
|
-
### getTimetablePages(query, fields, sortBy)
|
|
1103
|
+
### getTimetablePages(query, fields, sortBy, options)
|
|
1085
1104
|
|
|
1086
|
-
|
|
1105
|
+
Returns an array of timetable_pages that match query parameters. This is for the non-standard `timetable_pages.txt` file used in GTFS-to-HTML. [Details on timetable_pages.txt](https://gtfstohtml.com/docs/timetable-pages)
|
|
1087
1106
|
|
|
1088
1107
|
```js
|
|
1089
1108
|
import { getTimetablePages } from 'gtfs';
|
|
1090
1109
|
|
|
1091
1110
|
// Get all timetable_pages for an agency
|
|
1092
|
-
const timetablePages =
|
|
1111
|
+
const timetablePages = getTimetablePages();
|
|
1093
1112
|
|
|
1094
1113
|
// Get a specific timetable_page
|
|
1095
|
-
const timetablePages =
|
|
1114
|
+
const timetablePages = getTimetablePages({
|
|
1096
1115
|
timetable_page_id: '2',
|
|
1097
1116
|
});
|
|
1098
1117
|
```
|
|
1099
1118
|
|
|
1100
|
-
### getTimetableNotes(query, fields, sortBy)
|
|
1119
|
+
### getTimetableNotes(query, fields, sortBy, options)
|
|
1101
1120
|
|
|
1102
|
-
|
|
1121
|
+
Returns an array of timetable_notes that match query parameters. This is for the non-standard `timetable_notes.txt` file used in GTFS-to-HTML. [Details on timetable_notes.txt](https://gtfstohtml.com/docs/timetable-notes)
|
|
1103
1122
|
|
|
1104
1123
|
```js
|
|
1105
1124
|
import { getTimetableNotes } from 'gtfs';
|
|
1106
1125
|
|
|
1107
1126
|
// Get all timetable_notes for an agency
|
|
1108
|
-
const timetableNotes =
|
|
1127
|
+
const timetableNotes = getTimetableNotes();
|
|
1109
1128
|
|
|
1110
1129
|
// Get a specific timetable_note
|
|
1111
|
-
const timetableNotes =
|
|
1130
|
+
const timetableNotes = getTimetableNotes({
|
|
1112
1131
|
note_id: '1',
|
|
1113
1132
|
});
|
|
1114
1133
|
```
|
|
1115
1134
|
|
|
1116
|
-
### getTimetableNotesReferences(query, fields, sortBy)
|
|
1135
|
+
### getTimetableNotesReferences(query, fields, sortBy, options)
|
|
1117
1136
|
|
|
1118
|
-
|
|
1137
|
+
Returns an array of timetable_notes_references that match query parameters. This is for the non-standard `timetable_notes_references.txt` file used in GTFS-to-HTML. [Details on timetable_notes_references.txt](https://gtfstohtml.com/docs/timetable-notes-references)
|
|
1119
1138
|
|
|
1120
1139
|
```js
|
|
1121
1140
|
import { getTimetableNotesReferences } from 'gtfs';
|
|
1122
1141
|
|
|
1123
1142
|
// Get all timetable_notes_references for an agency
|
|
1124
|
-
const timetableNotesReferences =
|
|
1143
|
+
const timetableNotesReferences = getTimetableNotesReferences();
|
|
1125
1144
|
|
|
1126
1145
|
// Get all timetable_notes_references for a specific timetable
|
|
1127
|
-
const timetableNotesReferences =
|
|
1146
|
+
const timetableNotesReferences = getTimetableNotesReferences({
|
|
1128
1147
|
timetable_id: '4',
|
|
1129
1148
|
});
|
|
1130
1149
|
```
|
|
1131
1150
|
|
|
1132
|
-
### getTripsDatedVehicleJourneys(query, fields, sortBy)
|
|
1151
|
+
### getTripsDatedVehicleJourneys(query, fields, sortBy, options)
|
|
1133
1152
|
|
|
1134
|
-
|
|
1153
|
+
Returns an array of trips_dated_vehicle_journey that match query parameters. This is for the non-standard `trips_dated_vehicle_journey.txt` file. [Details on trips_dated_vehicle_journey.txt](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/)
|
|
1135
1154
|
|
|
1136
1155
|
```js
|
|
1137
1156
|
import { getTripsDatedVehicleJourneys } from 'gtfs';
|
|
1138
1157
|
|
|
1139
1158
|
// Get all timetable_stop_orders
|
|
1140
|
-
const tripsDatedVehicleJourneys =
|
|
1159
|
+
const tripsDatedVehicleJourneys = getTripsDatedVehicleJourneys();
|
|
1141
1160
|
```
|
|
1142
1161
|
|
|
1143
|
-
### getServiceAlerts(query, fields, sortBy)
|
|
1162
|
+
### getServiceAlerts(query, fields, sortBy, options)
|
|
1144
1163
|
|
|
1145
|
-
|
|
1146
|
-
These are only valid if you use GTFS-Realtime and have imported Service Alert data.
|
|
1164
|
+
Returns an array of GTFS Realtime service alerts that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Service Alerts](https://gtfs.org/realtime/feed-entities/service-alerts/)
|
|
1147
1165
|
|
|
1148
1166
|
```js
|
|
1149
1167
|
import { getServiceAlerts } from 'gtfs';
|
|
1150
1168
|
|
|
1151
1169
|
// Get service alerts
|
|
1152
|
-
const serviceAlerts =
|
|
1170
|
+
const serviceAlerts = getServiceAlerts();
|
|
1153
1171
|
```
|
|
1154
1172
|
|
|
1155
|
-
### getTripUpdates(query, fields, sortBy)
|
|
1173
|
+
### getTripUpdates(query, fields, sortBy, options)
|
|
1156
1174
|
|
|
1157
|
-
|
|
1158
|
-
These are only valid if you use GTFS-Realtime and have imported Trip Update data.
|
|
1175
|
+
Returns an array of GTFS Realtime trip updates that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Trip Updates](https://gtfs.org/realtime/feed-entities/trip-updates/)
|
|
1159
1176
|
|
|
1160
1177
|
```js
|
|
1161
1178
|
import { getTripUpdates } from 'gtfs';
|
|
1162
1179
|
|
|
1163
1180
|
// Get all trip updates
|
|
1164
|
-
const tripUpdates =
|
|
1181
|
+
const tripUpdates = getTripUpdates();
|
|
1165
1182
|
```
|
|
1166
1183
|
|
|
1167
|
-
### getStopTimesUpdates(query, fields, sortBy)
|
|
1184
|
+
### getStopTimesUpdates(query, fields, sortBy, options)
|
|
1168
1185
|
|
|
1169
|
-
|
|
1170
|
-
These are only valid if you use GTFS-Realtime and have imported Trip Update data.
|
|
1186
|
+
Returns an array of GTFS Realtime stop time updates that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Stop Time Updates](https://gtfs.org/realtime/feed-entities/trip-updates/#stoptimeupdate)
|
|
1171
1187
|
|
|
1172
1188
|
```js
|
|
1173
1189
|
import { getStopTimesUpdates } from 'gtfs';
|
|
1174
1190
|
|
|
1175
1191
|
// Get all stop times updates
|
|
1176
|
-
const stopTimesUpdates =
|
|
1192
|
+
const stopTimesUpdates = getStopTimesUpdates();
|
|
1177
1193
|
```
|
|
1178
1194
|
|
|
1179
|
-
### getVehiclePositions(query, fields, sortBy)
|
|
1195
|
+
### getVehiclePositions(query, fields, sortBy, options)
|
|
1180
1196
|
|
|
1181
|
-
|
|
1182
|
-
These are only valid if you use GTFS-Realtime and have imported Vehicle Position data.
|
|
1197
|
+
Returns an array of GTFS Realtime vehicle positions that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Vehicle Positions](https://gtfs.org/realtime/feed-entities/vehicle-positions/)
|
|
1183
1198
|
|
|
1184
1199
|
```js
|
|
1185
1200
|
import { getVehiclePositions } from 'gtfs';
|
|
1186
1201
|
|
|
1187
1202
|
// Get all vehicle position data
|
|
1188
|
-
const vehiclePositions =
|
|
1203
|
+
const vehiclePositions = getVehiclePositions();
|
|
1189
1204
|
```
|
|
1190
1205
|
|
|
1191
1206
|
### advancedQuery(table, advancedQueryOptions)
|
|
1192
1207
|
|
|
1193
|
-
Queries the database
|
|
1194
|
-
The result of the promise is an array the selected data. Example shows joining stop_times with trips.
|
|
1195
|
-
Used for advanced scenarios.
|
|
1208
|
+
Queries the database with support for table joins and custom tables and returns an array of data.
|
|
1196
1209
|
|
|
1197
1210
|
```js
|
|
1198
1211
|
import { advancedQuery } from 'gtfs';
|
|
1199
1212
|
|
|
1213
|
+
// Example `advancedQuery` joining stop_times with trips.
|
|
1200
1214
|
const advancedQueryOptions = {
|
|
1201
1215
|
query: {
|
|
1202
1216
|
'stop_times.trip_id': tripId,
|
|
@@ -1211,33 +1225,39 @@ const advancedQueryOptions = {
|
|
|
1211
1225
|
],
|
|
1212
1226
|
};
|
|
1213
1227
|
|
|
1214
|
-
|
|
1215
|
-
const stoptimes = await advancedQuery('stop_times', advancedQueryOptions);
|
|
1228
|
+
const stoptimes = advancedQuery('stop_times', advancedQueryOptions);
|
|
1216
1229
|
```
|
|
1217
1230
|
|
|
1218
|
-
###
|
|
1231
|
+
### Raw SQLite Query
|
|
1219
1232
|
|
|
1220
|
-
|
|
1221
|
-
The result of the promise is an array the selected data.
|
|
1233
|
+
Use the `openDb` function to get the db object, and then use any query method from [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) to query GTFS data.
|
|
1222
1234
|
|
|
1223
1235
|
```js
|
|
1224
|
-
import {
|
|
1236
|
+
import { openDb } from 'gtfs';
|
|
1237
|
+
const db = openDb(config);
|
|
1225
1238
|
|
|
1226
|
-
//
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
);
|
|
1230
|
-
```
|
|
1239
|
+
// Get a specific trip
|
|
1240
|
+
const statement = db.prepare('SELECT * FROM trips WHERE trip_id = ?');
|
|
1241
|
+
const trip = statement.get('123');
|
|
1231
1242
|
|
|
1232
|
-
|
|
1243
|
+
// Get all stops
|
|
1244
|
+
const stops = db.prepare('SELECT * from stops').all();
|
|
1233
1245
|
|
|
1234
|
-
|
|
1246
|
+
// Get all calendar_ids for specific date
|
|
1247
|
+
const statement = db.prepare(
|
|
1248
|
+
'SELECT service_id from calendar WHERE start_date <= $date AND end_date >= $date'
|
|
1249
|
+
);
|
|
1250
|
+
const calendarIds = statement.all({ date: 20150101 });
|
|
1235
1251
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1252
|
+
// Find all stops for route_id=18 by joining tables
|
|
1253
|
+
const statement = db.prepare(
|
|
1254
|
+
'SELECT DISTINCT stops.stop_id from stops INNER JOIN stop_times ON stops.stop_id = stop_times.stop_id INNER JOIN trips on trips.trip_id = stop_times.trip_id WHERE trips.route_id = ?'
|
|
1255
|
+
);
|
|
1256
|
+
const calendarIds = statement.all('18');
|
|
1238
1257
|
|
|
1239
|
-
//
|
|
1240
|
-
|
|
1258
|
+
// Execute raw SQL
|
|
1259
|
+
const sql = "DELETE FROM trips where trip_id = '329'";
|
|
1260
|
+
db.exec(sql);
|
|
1241
1261
|
```
|
|
1242
1262
|
|
|
1243
1263
|
## Contributing
|