gtfs 4.11.3 → 4.13.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/README.md +27 -5
- package/dist/bin/gtfs-export.d.ts +1 -0
- package/dist/bin/gtfs-export.js +3646 -0
- package/dist/bin/gtfs-export.js.map +1 -0
- package/dist/bin/gtfs-import.d.ts +1 -0
- package/dist/bin/gtfs-import.js +4146 -0
- package/dist/bin/gtfs-import.js.map +1 -0
- package/dist/bin/gtfsrealtime-update.d.ts +1 -0
- package/dist/bin/gtfsrealtime-update.js +3802 -0
- package/dist/bin/gtfsrealtime-update.js.map +1 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.js +5205 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -13
- package/.eslintrc.json +0 -28
- package/.github/workflows/nodejs.yml +0 -21
- package/.husky/pre-commit +0 -4
- package/@types/index.d.ts +0 -606
- package/@types/tests.ts +0 -31
- package/@types/tsconfig.json +0 -17
- package/CHANGELOG.md +0 -895
- package/bin/gtfs-export.js +0 -42
- package/bin/gtfs-import.js +0 -52
- package/bin/gtfsrealtime-update.js +0 -35
- package/config-sample-full.json +0 -20
- package/config-sample-rtupdates.json +0 -16
- package/config-sample.json +0 -8
- package/docs/images/node-gtfs-logo.svg +0 -18
- package/index.js +0 -1
- package/lib/advancedQuery.js +0 -36
- package/lib/db.js +0 -92
- package/lib/export.js +0 -141
- package/lib/file-utils.js +0 -103
- package/lib/geojson-utils.js +0 -138
- package/lib/gtfs/agencies.js +0 -32
- package/lib/gtfs/areas.js +0 -27
- package/lib/gtfs/attributions.js +0 -32
- package/lib/gtfs/booking-rules.js +0 -32
- package/lib/gtfs/calendar-dates.js +0 -32
- package/lib/gtfs/calendars.js +0 -32
- package/lib/gtfs/fare-attributes.js +0 -32
- package/lib/gtfs/fare-leg-rules.js +0 -32
- package/lib/gtfs/fare-media.js +0 -32
- package/lib/gtfs/fare-products.js +0 -32
- package/lib/gtfs/fare-rules.js +0 -32
- package/lib/gtfs/fare-transfer-rules.js +0 -32
- package/lib/gtfs/feed-info.js +0 -32
- package/lib/gtfs/frequencies.js +0 -32
- package/lib/gtfs/levels.js +0 -27
- package/lib/gtfs/location-group-stops.js +0 -32
- package/lib/gtfs/location-groups.js +0 -32
- package/lib/gtfs/locations.js +0 -32
- package/lib/gtfs/networks.js +0 -32
- package/lib/gtfs/pathways.js +0 -32
- package/lib/gtfs/route-networks.js +0 -32
- package/lib/gtfs/routes.js +0 -56
- package/lib/gtfs/shapes.js +0 -119
- package/lib/gtfs/stop-areas.js +0 -32
- package/lib/gtfs/stop-times.js +0 -32
- package/lib/gtfs/stops.js +0 -136
- package/lib/gtfs/timeframes.js +0 -32
- package/lib/gtfs/transfers.js +0 -32
- package/lib/gtfs/translations.js +0 -32
- package/lib/gtfs/trips.js +0 -27
- package/lib/gtfs-plus/calendar-attributes.js +0 -32
- package/lib/gtfs-plus/directions.js +0 -32
- package/lib/gtfs-plus/route-attributes.js +0 -32
- package/lib/gtfs-plus/stop-attributes.js +0 -32
- package/lib/gtfs-realtime/service-alerts.js +0 -34
- package/lib/gtfs-realtime/stop-time-updates.js +0 -32
- package/lib/gtfs-realtime/trip-updates.js +0 -32
- package/lib/gtfs-realtime/vehicle-positions.js +0 -32
- package/lib/gtfs-ride/board-alights.js +0 -32
- package/lib/gtfs-ride/ride-feed-infos.js +0 -32
- package/lib/gtfs-ride/rider-trips.js +0 -32
- package/lib/gtfs-ride/riderships.js +0 -32
- package/lib/gtfs-ride/trip-capacities.js +0 -32
- package/lib/gtfs.js +0 -261
- package/lib/import.js +0 -803
- package/lib/log-utils.js +0 -73
- package/lib/non-standard/timetable-notes-references.js +0 -32
- package/lib/non-standard/timetable-notes.js +0 -32
- package/lib/non-standard/timetable-pages.js +0 -32
- package/lib/non-standard/timetable-stop-order.js +0 -32
- package/lib/non-standard/timetables.js +0 -32
- package/lib/non-standard/trips-dated-vehicle-journey.js +0 -32
- package/lib/ods/deadhead-times.js +0 -32
- package/lib/ods/deadheads.js +0 -32
- package/lib/ods/ops-locations.js +0 -32
- package/lib/ods/run-events.js +0 -32
- package/lib/ods/runs-pieces.js +0 -32
- package/lib/utils.js +0 -178
- package/models/gtfs/agency.js +0 -49
- package/models/gtfs/areas.js +0 -19
- package/models/gtfs/attributions.js +0 -68
- package/models/gtfs/booking-rules.js +0 -92
- package/models/gtfs/calendar-dates.js +0 -34
- package/models/gtfs/calendar.js +0 -76
- package/models/gtfs/fare-attributes.js +0 -48
- package/models/gtfs/fare-leg-rules.js +0 -55
- package/models/gtfs/fare-media.js +0 -26
- package/models/gtfs/fare-products.js +0 -35
- package/models/gtfs/fare-rules.js +0 -34
- package/models/gtfs/fare-transfer-rules.js +0 -56
- package/models/gtfs/feed-info.js +0 -50
- package/models/gtfs/frequencies.js +0 -46
- package/models/gtfs/levels.js +0 -25
- package/models/gtfs/location-group-stops.js +0 -22
- package/models/gtfs/location-groups.js +0 -19
- package/models/gtfs/locations.js +0 -12
- package/models/gtfs/networks.js +0 -20
- package/models/gtfs/pathways.js +0 -74
- package/models/gtfs/route-networks.js +0 -21
- package/models/gtfs/routes.js +0 -79
- package/models/gtfs/shapes.js +0 -41
- package/models/gtfs/stop-areas.js +0 -20
- package/models/gtfs/stop-times.js +0 -120
- package/models/gtfs/stops.js +0 -85
- package/models/gtfs/timeframes.js +0 -29
- package/models/gtfs/transfers.js +0 -56
- package/models/gtfs/translations.js +0 -48
- package/models/gtfs/trips.js +0 -70
- package/models/gtfs-plus/calendar-attributes.js +0 -22
- package/models/gtfs-plus/directions.js +0 -29
- package/models/gtfs-plus/route-attributes.js +0 -34
- package/models/gtfs-plus/stop-attributes.js +0 -35
- package/models/gtfs-realtime/service-alert-targets.js +0 -37
- package/models/gtfs-realtime/service-alerts.js +0 -60
- package/models/gtfs-realtime/stop-time-updates.js +0 -85
- package/models/gtfs-realtime/trip-updates.js +0 -75
- package/models/gtfs-realtime/vehicle-positions.js +0 -135
- package/models/gtfs-ride/board-alight.js +0 -132
- package/models/gtfs-ride/ride-feed-info.js +0 -40
- package/models/gtfs-ride/rider-trip.js +0 -113
- package/models/gtfs-ride/ridership.js +0 -127
- package/models/gtfs-ride/trip-capacity.js +0 -51
- package/models/models.js +0 -120
- package/models/non-standard/timetable-notes-references.js +0 -50
- package/models/non-standard/timetable-notes.js +0 -24
- package/models/non-standard/timetable-pages.js +0 -23
- package/models/non-standard/timetable-stop-order.js +0 -32
- package/models/non-standard/timetables.js +0 -144
- package/models/non-standard/trips-dated-vehicle-journey.js +0 -34
- package/models/ods/deadhead-times.js +0 -65
- package/models/ods/deadheads.js +0 -60
- package/models/ods/ops-locations.js +0 -46
- package/models/ods/run-events.js +0 -70
- package/models/ods/runs-pieces.js +0 -59
- package/test/fixture/caltrain_20160406.zip +0 -0
- package/test/mocha/advanced-query.js +0 -74
- package/test/mocha/delete-db.js +0 -62
- package/test/mocha/export-gtfs.js +0 -147
- package/test/mocha/fare-transfer-rules.js +0 -32
- package/test/mocha/get-agencies.js +0 -90
- package/test/mocha/get-areas.js +0 -27
- package/test/mocha/get-attributions.js +0 -27
- package/test/mocha/get-board-alights.js +0 -28
- package/test/mocha/get-booking-rules.js +0 -28
- package/test/mocha/get-calendar-attributes.js +0 -33
- package/test/mocha/get-calendar-dates.js +0 -107
- package/test/mocha/get-calendars.js +0 -94
- package/test/mocha/get-directions.js +0 -28
- package/test/mocha/get-fare-attributes.js +0 -51
- package/test/mocha/get-fare-leg-rules.js +0 -27
- package/test/mocha/get-fare-media.js +0 -27
- package/test/mocha/get-fare-products.js +0 -27
- package/test/mocha/get-fare-rules.js +0 -50
- package/test/mocha/get-feed-info.js +0 -28
- package/test/mocha/get-frequencies.js +0 -28
- package/test/mocha/get-levels.js +0 -28
- package/test/mocha/get-location-group-stops.js +0 -33
- package/test/mocha/get-location-groups.js +0 -28
- package/test/mocha/get-locations.js +0 -69
- package/test/mocha/get-networks.js +0 -28
- package/test/mocha/get-pathways.js +0 -28
- package/test/mocha/get-ride-feed-infos.js +0 -24
- package/test/mocha/get-rider-trips.js +0 -28
- package/test/mocha/get-riderships.js +0 -28
- package/test/mocha/get-route-attributes.js +0 -33
- package/test/mocha/get-route-networks.js +0 -28
- package/test/mocha/get-routes.js +0 -143
- package/test/mocha/get-shapes-as-geojson.js +0 -92
- package/test/mocha/get-shapes.js +0 -240
- package/test/mocha/get-stop-attributes.js +0 -28
- package/test/mocha/get-stops-as-geojson.js +0 -87
- package/test/mocha/get-stops.js +0 -343
- package/test/mocha/get-stoptimes.js +0 -67
- package/test/mocha/get-timeframes.js +0 -28
- package/test/mocha/get-timetable-pages.js +0 -28
- package/test/mocha/get-timetable-stop-orders.js +0 -33
- package/test/mocha/get-timetables.js +0 -28
- package/test/mocha/get-transfers.js +0 -28
- package/test/mocha/get-translations.js +0 -28
- package/test/mocha/get-trip-capacities.js +0 -28
- package/test/mocha/get-trips.js +0 -53
- package/test/mocha/import-gtfs.js +0 -173
- package/test/mocha/open-db.js +0 -149
- package/test/mocha/raw-query.js +0 -34
- package/test/test-config.js +0 -12
package/lib/gtfs/locations.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import locations from '../../models/gtfs/locations.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all locations that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getLocations(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(locations.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/networks.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import networks from '../../models/gtfs/networks.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all networks that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getNetworks(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(networks.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/pathways.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import pathways from '../../models/gtfs/pathways.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all pathways that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getPathways(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(pathways.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import routeNetworks from '../../models/gtfs/route-networks.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all route_networks that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getRouteNetworks(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(routeNetworks.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/routes.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { omit, pick } from 'lodash-es';
|
|
2
|
-
import sqlString from 'sqlstring-sqlite';
|
|
3
|
-
|
|
4
|
-
import { openDb } from '../db.js';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
formatOrderByClause,
|
|
8
|
-
formatSelectClause,
|
|
9
|
-
formatWhereClause,
|
|
10
|
-
formatWhereClauses,
|
|
11
|
-
} from '../utils.js';
|
|
12
|
-
import routes from '../../models/gtfs/routes.js';
|
|
13
|
-
|
|
14
|
-
function buildStoptimeSubquery(query) {
|
|
15
|
-
const whereClause = formatWhereClauses(query);
|
|
16
|
-
return `SELECT DISTINCT trip_id FROM stop_times ${whereClause}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function buildTripSubquery(query) {
|
|
20
|
-
return `SELECT DISTINCT route_id FROM trips WHERE trip_id IN (${buildStoptimeSubquery(
|
|
21
|
-
query,
|
|
22
|
-
)})`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
* Returns an array of routes that match the query parameters. A `stop_id`
|
|
27
|
-
* query parameter may be passed to find all routes that contain that stop.
|
|
28
|
-
*/
|
|
29
|
-
export function getRoutes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
30
|
-
const db = options.db ?? openDb();
|
|
31
|
-
const tableName = sqlString.escapeId(routes.filenameBase);
|
|
32
|
-
const selectClause = formatSelectClause(fields);
|
|
33
|
-
let whereClause = '';
|
|
34
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
35
|
-
|
|
36
|
-
const routeQuery = omit(query, ['stop_id']);
|
|
37
|
-
const stoptimeQuery = pick(query, ['stop_id']);
|
|
38
|
-
|
|
39
|
-
const whereClauses = Object.entries(routeQuery).map(([key, value]) =>
|
|
40
|
-
formatWhereClause(key, value),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
if (Object.values(stoptimeQuery).length > 0) {
|
|
44
|
-
whereClauses.push(`route_id IN (${buildTripSubquery(stoptimeQuery)})`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (whereClauses.length > 0) {
|
|
48
|
-
whereClause = `WHERE ${whereClauses.join(' AND ')}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return db
|
|
52
|
-
.prepare(
|
|
53
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
54
|
-
)
|
|
55
|
-
.all();
|
|
56
|
-
}
|
package/lib/gtfs/shapes.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { omit, pick } from 'lodash-es';
|
|
2
|
-
import sqlString from 'sqlstring-sqlite';
|
|
3
|
-
import { featureCollection } from '@turf/helpers';
|
|
4
|
-
|
|
5
|
-
import { openDb } from '../db.js';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
formatOrderByClause,
|
|
9
|
-
formatSelectClause,
|
|
10
|
-
formatWhereClause,
|
|
11
|
-
formatWhereClauses,
|
|
12
|
-
} from '../utils.js';
|
|
13
|
-
import { shapesToGeoJSONFeatures } from '../geojson-utils.js';
|
|
14
|
-
import shapes from '../../models/gtfs/shapes.js';
|
|
15
|
-
import { getAgencies } from './agencies.js';
|
|
16
|
-
import { getRoutes } from './routes.js';
|
|
17
|
-
import { getRouteAttributes } from '../gtfs-plus/route-attributes.js';
|
|
18
|
-
|
|
19
|
-
function buildTripSubquery(query) {
|
|
20
|
-
const whereClause = formatWhereClauses(query);
|
|
21
|
-
return `SELECT DISTINCT shape_id FROM trips ${whereClause}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
* Returns array of shapes that match the query parameters. A `route_id` query
|
|
26
|
-
* parameter may be passed to find all shapes for a route. A `trip_id` query
|
|
27
|
-
* parameter may be passed to find all shapes for a trip. A `direction_id`
|
|
28
|
-
* query parameter may be passed to find all shapes for a direction.
|
|
29
|
-
*/
|
|
30
|
-
export function getShapes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
31
|
-
const db = options.db ?? openDb();
|
|
32
|
-
const tableName = sqlString.escapeId(shapes.filenameBase);
|
|
33
|
-
const selectClause = formatSelectClause(fields);
|
|
34
|
-
let whereClause = '';
|
|
35
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
36
|
-
|
|
37
|
-
const shapeQuery = omit(query, [
|
|
38
|
-
'route_id',
|
|
39
|
-
'trip_id',
|
|
40
|
-
'service_id',
|
|
41
|
-
'direction_id',
|
|
42
|
-
]);
|
|
43
|
-
const tripQuery = pick(query, [
|
|
44
|
-
'route_id',
|
|
45
|
-
'trip_id',
|
|
46
|
-
'service_id',
|
|
47
|
-
'direction_id',
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
const whereClauses = Object.entries(shapeQuery).map(([key, value]) =>
|
|
51
|
-
formatWhereClause(key, value),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if (Object.values(tripQuery).length > 0) {
|
|
55
|
-
whereClauses.push(`shape_id IN (${buildTripSubquery(tripQuery)})`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (whereClauses.length > 0) {
|
|
59
|
-
whereClause = `WHERE ${whereClauses.join(' AND ')}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return db
|
|
63
|
-
.prepare(
|
|
64
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
65
|
-
)
|
|
66
|
-
.all();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/*
|
|
70
|
-
* Returns geoJSON of the shapes that match the query parameters. A `route_id`
|
|
71
|
-
* query parameter may be passed to find all shapes for a route. A `trip_id`
|
|
72
|
-
* query parameter may be passed to find all shapes for a trip. A
|
|
73
|
-
* `direction_id` query parameter may be passed to find all shapes for a direction.
|
|
74
|
-
*/
|
|
75
|
-
export function getShapesAsGeoJSON(query = {}, options = {}) {
|
|
76
|
-
const agencies = getAgencies({}, [], [], options);
|
|
77
|
-
|
|
78
|
-
const routeQuery = {};
|
|
79
|
-
|
|
80
|
-
if (query.route_id !== undefined) {
|
|
81
|
-
routeQuery.route_id = query.route_id;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const routes = getRoutes(routeQuery, [], [], options);
|
|
85
|
-
const features = [];
|
|
86
|
-
|
|
87
|
-
for (const route of routes) {
|
|
88
|
-
const shapeQuery = {
|
|
89
|
-
route_id: route.route_id,
|
|
90
|
-
...omit(query, 'route_id'),
|
|
91
|
-
};
|
|
92
|
-
const shapes = getShapes(
|
|
93
|
-
shapeQuery,
|
|
94
|
-
['shape_id', 'shape_pt_sequence', 'shape_pt_lon', 'shape_pt_lat'],
|
|
95
|
-
[],
|
|
96
|
-
options,
|
|
97
|
-
);
|
|
98
|
-
const routeAttributes = getRouteAttributes(
|
|
99
|
-
{ route_id: route.route_id },
|
|
100
|
-
[],
|
|
101
|
-
[],
|
|
102
|
-
options,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const agency = agencies.find(
|
|
106
|
-
(agency) => agency.agency_id === route.agency_id,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const geojsonProperties = {
|
|
110
|
-
agency_name: agency ? agency.agency_name : undefined,
|
|
111
|
-
shape_id: query.shape_id,
|
|
112
|
-
...route,
|
|
113
|
-
...(routeAttributes?.[0] || []),
|
|
114
|
-
};
|
|
115
|
-
features.push(...shapesToGeoJSONFeatures(shapes, geojsonProperties));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return featureCollection(features);
|
|
119
|
-
}
|
package/lib/gtfs/stop-areas.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import stopAreas from '../../models/gtfs/stop-areas.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all stop areas that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getStopAreas(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(stopAreas.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/stop-times.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import stopTimes from '../../models/gtfs/stop-times.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of stoptimes that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getStoptimes(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(stopTimes.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/stops.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { omit, orderBy, pick } from 'lodash-es';
|
|
2
|
-
import sqlString from 'sqlstring-sqlite';
|
|
3
|
-
|
|
4
|
-
import { openDb } from '../db.js';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
formatOrderByClause,
|
|
8
|
-
formatSelectClause,
|
|
9
|
-
formatWhereClause,
|
|
10
|
-
formatWhereClauseBoundingBox,
|
|
11
|
-
formatWhereClauses,
|
|
12
|
-
} from '../utils.js';
|
|
13
|
-
import { stopsToGeoJSON } from '../geojson-utils.js';
|
|
14
|
-
import stops from '../../models/gtfs/stops.js';
|
|
15
|
-
import { getAgencies } from './agencies.js';
|
|
16
|
-
import { getStopAttributes } from '../gtfs-plus/stop-attributes.js';
|
|
17
|
-
|
|
18
|
-
function buildTripSubquery(query) {
|
|
19
|
-
const whereClause = formatWhereClauses(query);
|
|
20
|
-
return `SELECT trip_id FROM trips ${whereClause}`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function buildStoptimeSubquery(query) {
|
|
24
|
-
return `SELECT DISTINCT stop_id FROM stop_times WHERE trip_id IN (${buildTripSubquery(
|
|
25
|
-
query,
|
|
26
|
-
)})`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
* Returns an array of stops that match the query parameters. A `route_id`
|
|
31
|
-
* query parameter may be passed to find all shapes for a route. A `trip_id`
|
|
32
|
-
* query parameter may be passed to find all shapes for a trip. A
|
|
33
|
-
* `direction_id` query parameter may be passed to find all shapes for a
|
|
34
|
-
* direction.
|
|
35
|
-
*/
|
|
36
|
-
export function getStops(query = {}, fields = [], orderBy = [], options = {}) {
|
|
37
|
-
const db = options.db ?? openDb();
|
|
38
|
-
const tableName = sqlString.escapeId(stops.filenameBase);
|
|
39
|
-
const selectClause = formatSelectClause(fields);
|
|
40
|
-
let whereClause = '';
|
|
41
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
42
|
-
|
|
43
|
-
const stopQueryOmitKeys = [
|
|
44
|
-
'route_id',
|
|
45
|
-
'trip_id',
|
|
46
|
-
'service_id',
|
|
47
|
-
'direction_id',
|
|
48
|
-
'shape_id',
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
// If bounding_box_side_m is defined, search for stops inside a bounding box so omit `stop_lat` and `stop_lon`.
|
|
52
|
-
if (options.bounding_box_side_m !== undefined) {
|
|
53
|
-
stopQueryOmitKeys.push('stop_lat', 'stop_lon');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let stopQuery = omit(query, stopQueryOmitKeys);
|
|
57
|
-
|
|
58
|
-
const tripQuery = pick(query, [
|
|
59
|
-
'route_id',
|
|
60
|
-
'trip_id',
|
|
61
|
-
'service_id',
|
|
62
|
-
'direction_id',
|
|
63
|
-
'shape_id',
|
|
64
|
-
]);
|
|
65
|
-
|
|
66
|
-
const whereClauses = Object.entries(stopQuery).map(([key, value]) =>
|
|
67
|
-
formatWhereClause(key, value),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
options.bounding_box_side_m !== undefined &&
|
|
72
|
-
query.stop_lat !== undefined &&
|
|
73
|
-
query.stop_lon !== undefined
|
|
74
|
-
) {
|
|
75
|
-
whereClauses.push(
|
|
76
|
-
formatWhereClauseBoundingBox(
|
|
77
|
-
query.stop_lat,
|
|
78
|
-
query.stop_lon,
|
|
79
|
-
options.bounding_box_side_m,
|
|
80
|
-
),
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (Object.values(tripQuery).length > 0) {
|
|
85
|
-
whereClauses.push(`stop_id IN (${buildStoptimeSubquery(tripQuery)})`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (whereClauses.length > 0) {
|
|
89
|
-
whereClause = `WHERE ${whereClauses.join(' AND ')}`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return db
|
|
93
|
-
.prepare(
|
|
94
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
95
|
-
)
|
|
96
|
-
.all();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/*
|
|
100
|
-
* Returns geoJSON with stops. A `route_id` query parameter may be passed to
|
|
101
|
-
* find all shapes for a route. A `trip_id` query parameter may be passed to
|
|
102
|
-
* find all shapes for a trip. A `direction_id` query parameter may be passed
|
|
103
|
-
* to find all shapes for a direction.
|
|
104
|
-
*/
|
|
105
|
-
export function getStopsAsGeoJSON(query = {}, options = {}) {
|
|
106
|
-
const db = options.db ?? openDb();
|
|
107
|
-
const stops = getStops(query, [], [], options);
|
|
108
|
-
|
|
109
|
-
// Get all agencies for reference
|
|
110
|
-
const agencies = getAgencies({}, [], [], options);
|
|
111
|
-
|
|
112
|
-
const preparedStops = stops.map((stop) => {
|
|
113
|
-
const routeSubquery =
|
|
114
|
-
'SELECT DISTINCT route_id FROM trips WHERE trip_id IN (SELECT DISTINCT trip_id FROM stop_times WHERE stop_id = ?)';
|
|
115
|
-
const routes = db
|
|
116
|
-
.prepare(`SELECT * FROM routes WHERE route_id IN (${routeSubquery})`)
|
|
117
|
-
.all(stop.stop_id);
|
|
118
|
-
|
|
119
|
-
const stopAttributes = getStopAttributes({ stop_id: stop.stop_id });
|
|
120
|
-
|
|
121
|
-
stop.routes = orderBy(routes, (route) =>
|
|
122
|
-
Number.parseInt(route.route_short_name, 10),
|
|
123
|
-
);
|
|
124
|
-
stop.agency_name = agencies[0].agency_name;
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
...stop,
|
|
128
|
-
...(stopAttributes?.[0] || []),
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Exclude stops not part of any route
|
|
133
|
-
const filteredStops = preparedStops.filter((stop) => stop.routes.length > 0);
|
|
134
|
-
|
|
135
|
-
return stopsToGeoJSON(filteredStops);
|
|
136
|
-
}
|
package/lib/gtfs/timeframes.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import timeframes from '../../models/gtfs/timeframes.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all timeframes that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getTimeframes(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(timeframes.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/transfers.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import transfers from '../../models/gtfs/transfers.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all transfers that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getTransfers(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(transfers.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/translations.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import translations from '../../models/gtfs/translations.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all translations that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getTranslations(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(translations.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|
package/lib/gtfs/trips.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import trips from '../../models/gtfs/trips.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all trips that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getTrips(query = {}, fields = [], orderBy = [], options = {}) {
|
|
16
|
-
const db = options.db ?? openDb();
|
|
17
|
-
const tableName = sqlString.escapeId(trips.filenameBase);
|
|
18
|
-
const selectClause = formatSelectClause(fields);
|
|
19
|
-
const whereClause = formatWhereClauses(query);
|
|
20
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
21
|
-
|
|
22
|
-
return db
|
|
23
|
-
.prepare(
|
|
24
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
25
|
-
)
|
|
26
|
-
.all();
|
|
27
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import sqlString from 'sqlstring-sqlite';
|
|
2
|
-
|
|
3
|
-
import { openDb } from '../db.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
formatOrderByClause,
|
|
7
|
-
formatSelectClause,
|
|
8
|
-
formatWhereClauses,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
import calendarAttributes from '../../models/gtfs-plus/calendar-attributes.js';
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Returns an array of all calendar_attributes that match the query parameters.
|
|
14
|
-
*/
|
|
15
|
-
export function getCalendarAttributes(
|
|
16
|
-
query = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
orderBy = [],
|
|
19
|
-
options = {},
|
|
20
|
-
) {
|
|
21
|
-
const db = options.db ?? openDb();
|
|
22
|
-
const tableName = sqlString.escapeId(calendarAttributes.filenameBase);
|
|
23
|
-
const selectClause = formatSelectClause(fields);
|
|
24
|
-
const whereClause = formatWhereClauses(query);
|
|
25
|
-
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
-
|
|
27
|
-
return db
|
|
28
|
-
.prepare(
|
|
29
|
-
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
-
)
|
|
31
|
-
.all();
|
|
32
|
-
}
|