-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathgtfs_tables.sqlite
More file actions
321 lines (259 loc) · 10.4 KB
/
gtfs_tables.sqlite
File metadata and controls
321 lines (259 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
drop table if exists gtfs_agency;
drop table if exists gtfs_stops;
drop table if exists gtfs_routes;
drop table if exists gtfs_calendar;
drop table if exists gtfs_calendar_dates;
drop table if exists gtfs_fare_attributes;
drop table if exists gtfs_fare_rules;
drop table if exists gtfs_shapes;
drop table if exists gtfs_trips;
drop table if exists gtfs_stop_times;
drop table if exists gtfs_frequencies;
drop table if exists gtfs_transfers;
drop table if exists gtfs_feed_info;
drop table if exists gtfs_route_types;
drop table if exists gtfs_directions;
drop table if exists gtfs_pickup_dropoff_types;
drop table if exists gtfs_payment_methods;
drop table if exists gtfs_location_types;
drop table if exists gtfs_transfer_types;
drop table if exists service_combo_ids;
drop table if exists service_combinations;
PRAGMA foreign_keys = OFF;
begin;
create table gtfs_agency (
agency_id text PRIMARY KEY,--PRIMARY KEY,
agency_name text NOT NULL,--NOT NULL,
agency_url text NOT NULL,--NOT NULL,
agency_timezone text NOT NULL,--NOT NULL,
agency_lang text
-- unofficial features
,
agency_phone text,
fare_url text
);
--unoffical table, related to gtfs_stops(location_type)
create table gtfs_location_types (
location_type int PRIMARY KEY,
description text
);
insert into gtfs_location_types(location_type, description)
values (0,'stop');
insert into gtfs_location_types(location_type, description)
values (1,'station');
insert into gtfs_location_types(location_type, description)
values (2,'station entrance');
create table gtfs_stops (
stop_id text PRIMARY KEY,--PRIMARY KEY,
stop_name text NOT NULL, --NOT NULL,
stop_desc text,
stop_lat double precision,
stop_lon double precision,
zone_id int,
stop_url text,
stop_code text,
-- new
stop_street text,
stop_city text,
stop_region text,
stop_postcode text,
stop_country text,
-- unofficial features
location_type int, --FOREIGN KEY REFERENCES gtfs_location_types(location_type)
parent_station text, --FOREIGN KEY REFERENCES gtfs_stops(stop_id)
stop_timezone text,
FOREIGN KEY (location_type) REFERENCES gtfs_location_types(location_type),
FOREIGN KEY (parent_station) REFERENCES gtfs_stops(stop_id)
);
-- select AddGeometryColumn( 'gtfs_stops', 'location', #{WGS84_LATLONG_EPSG}, 'POINT', 2 );
-- CREATE INDEX gtfs_stops_location_ix ON gtfs_stops USING GIST ( location GIST_GEOMETRY_OPS );
create table gtfs_route_types (
route_type int PRIMARY KEY,
description text
);
insert into gtfs_route_types (route_type, description) values (0, 'Street Level Rail');
insert into gtfs_route_types (route_type, description) values (1, 'Underground Rail');
insert into gtfs_route_types (route_type, description) values (2, 'Intercity Rail');
insert into gtfs_route_types (route_type, description) values (3, 'Bus');
insert into gtfs_route_types (route_type, description) values (4, 'Ferry');
insert into gtfs_route_types (route_type, description) values (5, 'Cable Car');
insert into gtfs_route_types (route_type, description) values (6, 'Suspended Car');
insert into gtfs_route_types (route_type, description) values (7, 'Steep Incline Mode');
create table gtfs_routes (
route_id text PRIMARY KEY,--PRIMARY KEY,
agency_id text , --REFERENCES gtfs_agency(agency_id),
route_short_name text DEFAULT '',
route_long_name text DEFAULT '',
route_desc text,
route_type int , --REFERENCES gtfs_route_types(route_type),
route_url text,
route_color text,
route_text_color text,
FOREIGN KEY (agency_id) REFERENCES gtfs_agency(agency_id),
FOREIGN KEY (route_type) REFERENCES gtfs_route_types(route_type)
);
create table gtfs_directions (
direction_id int PRIMARY KEY,
description text
);
insert into gtfs_directions (direction_id, description) values (0,'This way');
insert into gtfs_directions (direction_id, description) values (1,'That way');
create table gtfs_pickup_dropoff_types (
type_id int PRIMARY KEY,
description text
);
insert into gtfs_pickup_dropoff_types (type_id, description) values (0,'Regularly Scheduled');
insert into gtfs_pickup_dropoff_types (type_id, description) values (1,'Not available');
insert into gtfs_pickup_dropoff_types (type_id, description) values (2,'Phone arrangement only');
insert into gtfs_pickup_dropoff_types (type_id, description) values (3,'Driver arrangement only');
-- CREATE INDEX gst_trip_id_stop_sequence ON gtfs_stop_times (trip_id, stop_sequence);
create table gtfs_calendar (
service_id text PRIMARY KEY,--PRIMARY KEY,
monday int NOT NULL, --NOT NULL,
tuesday int NOT NULL, --NOT NULL,
wednesday int NOT NULL, --NOT NULL,
thursday int NOT NULL, --NOT NULL,
friday int NOT NULL, --NOT NULL,
saturday int NOT NULL, --NOT NULL,
sunday int NOT NULL, --NOT NULL,
start_date date NOT NULL, --NOT NULL,
end_date date NOT NULL --NOT NULL
);
create table gtfs_calendar_dates (
service_id text , --REFERENCES gtfs_calendar(service_id),
date date NOT NULL, --NOT NULL,
exception_type int NOT NULL--NOT NULL
-- above reference not in makeindices.sql
);
-- The following two tables are not in the spec, but they make dealing with dates and services easier
create table service_combo_ids
(
combination_id serial --primary key
);
create table service_combinations
(
combination_id int , --references service_combo_ids(combination_id),
service_id text --references gtfs_calendar(service_id)
);
create table gtfs_payment_methods (
payment_method int PRIMARY KEY,
description text
);
insert into gtfs_payment_methods (payment_method, description) values (0,'On Board');
insert into gtfs_payment_methods (payment_method, description) values (1,'Prepay');
create table gtfs_fare_attributes (
fare_id text PRIMARY KEY,--PRIMARY KEY,
price double precision NOT NULL, --NOT NULL,
currency_type text NOT NULL, --NOT NULL,
payment_method int , --REFERENCES gtfs_payment_methods,
transfers int,
transfer_duration int,
agency_id text, --REFERENCES gtfs_agency(agency_id),
FOREIGN KEY (payment_method) REFERENCES gtfs_payment_methods(payment_method),
FOREIGN KEY (agency_id) REFERENCES gtfs_agency(agency_id)
);
create table gtfs_fare_rules (
fare_id text , --REFERENCES gtfs_fare_attributes(fare_id),
route_id text , --REFERENCES gtfs_routes(route_id),
origin_id int ,
destination_id int ,
contains_id int
-- unofficial features
,
service_id text, -- REFERENCES gtfs_calendar(service_id) ?
FOREIGN KEY (fare_id) REFERENCES gtfs_fare_attributes(fare_id),
FOREIGN KEY (route_id) REFERENCES gtfs_routes(route_id)
);
create table gtfs_shapes (
shape_id text NOT NULL, --NOT NULL,
shape_pt_lat double precision NOT NULL, --NOT NULL,
shape_pt_lon double precision NOT NULL, --NOT NULL,
shape_pt_sequence int NOT NULL, --NOT NULL,
shape_dist_traveled double precision
);
create table gtfs_trips (
route_id text , --REFERENCES gtfs_routes(route_id),
service_id text , --REFERENCES gtfs_calendar(service_id),
trip_id text PRIMARY KEY,--PRIMARY KEY,
trip_headsign text,
direction_id int NOT NULL, --NOT NULL --REFERENCES gtfs_directions(direction_id),
block_id text,
shape_id text,
-- unofficial features
trip_short_name text,
FOREIGN KEY (route_id) REFERENCES gtfs_routes(route_id),
FOREIGN KEY (direction_id) REFERENCES gtfs_directions(direction_id)
);
create table gtfs_stop_times (
trip_id text , --REFERENCES gtfs_trips(trip_id),
arrival_time text, -- CHECK (arrival_time LIKE '__:__:__'),
departure_time text, -- CHECK (departure_time LIKE '__:__:__'),
stop_id text , --REFERENCES gtfs_stops(stop_id),
stop_sequence int NOT NULL, --NOT NULL,
stop_headsign text,
pickup_type int , --REFERENCES gtfs_pickup_dropoff_types(type_id),
drop_off_type int , --REFERENCES gtfs_pickup_dropoff_types(type_id),
shape_dist_traveled double precision
-- unofficial features
,
timepoint int
-- the following are not in the spec
,
arrival_time_seconds int,
departure_time_seconds int,
FOREIGN KEY (trip_id) REFERENCES gtfs_trips(trip_id),
FOREIGN KEY (stop_id) REFERENCES gtfs_stops(stop_id),
FOREIGN KEY (pickup_type) REFERENCES gtfs_pickup_dropoff_types(type_id),
FOREIGN KEY (drop_off_type) REFERENCES gtfs_pickup_dropoff_types(type_id),
CHECK (arrival_time LIKE '__:__:__'),
CHECK (departure_time LIKE '__:__:__')
);
create index arr_time_index on gtfs_stop_times(arrival_time_seconds);
create index dep_time_index on gtfs_stop_times(departure_time_seconds);
create index stop_seq_index on gtfs_stop_times(trip_id,stop_sequence);
create index shape_seq_index on gtfs_shapes(shape_id,shape_pt_sequence);
-- select AddGeometryColumn( 'gtfs_shapes', 'shape', #{WGS84_LATLONG_EPSG}, 'LINESTRING', 2 );
create table gtfs_frequencies (
trip_id text , --REFERENCES gtfs_trips(trip_id),
start_time text NOT NULL, --NOT NULL,
end_time text NOT NULL, --NOT NULL,
headway_secs int NOT NULL, --NOT NULL
start_time_seconds int,
end_time_seconds int,
FOREIGN KEY (trip_id) REFERENCES gtfs_trips(trip_id)
);
-- unofficial tables
create table gtfs_transfer_types (
transfer_type int PRIMARY KEY,
description text
);
insert into gtfs_transfer_types (transfer_type, description)
values (0,'Preferred transfer point');
insert into gtfs_transfer_types (transfer_type, description)
values (1,'Designated transfer point');
insert into gtfs_transfer_types (transfer_type, description)
values (2,'Transfer possible with min_transfer_time window');
insert into gtfs_transfer_types (transfer_type, description)
values (3,'Transfers forbidden');
create table gtfs_transfers (
from_stop_id text, --REFERENCES gtfs_stops(stop_id)
to_stop_id text, --REFERENCES gtfs_stops(stop_id)
transfer_type int, --REFERENCES gtfs_transfer_types(transfer_type)
min_transfer_time int,
from_route_id text, --REFERENCES gtfs_routes(route_id)
to_route_id text, --REFERENCES gtfs_routes(route_id)
service_id text, --REFERENCES gtfs_calendar(service_id) ?
FOREIGN KEY (from_stop_id) REFERENCES gtfs_stops(stop_id),
FOREIGN KEY (to_stop_id) REFERENCES gtfs_stops(stop_id),
FOREIGN KEY (transfer_type) REFERENCES gtfs_transfer_types(transfer_type),
FOREIGN KEY (from_route_id) REFERENCES gtfs_routes(route_id),
FOREIGN KEY (to_route_id) REFERENCES gtfs_routes(route_id)
);
create table gtfs_feed_info (
feed_publisher_name text,
feed_publisher_url text,
feed_timezone text,
feed_lang text,
feed_version text
);
commit;