-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.sql
More file actions
287 lines (230 loc) · 10.1 KB
/
Copy pathdata.sql
File metadata and controls
287 lines (230 loc) · 10.1 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
drop table if exists gtfs_agency cascade;
drop table if exists gtfs_stops cascade;
drop table if exists gtfs_routes cascade;
drop table if exists gtfs_calendar cascade;
drop table if exists gtfs_calendar_dates cascade;
drop table if exists gtfs_fare_attributes cascade;
drop table if exists gtfs_fare_rules cascade;
drop table if exists gtfs_shapes cascade;
drop table if exists gtfs_trips cascade;
drop table if exists gtfs_stop_times cascade;
drop table if exists gtfs_frequencies cascade;
drop table if exists gtfs_transfers cascade;
drop table if exists gtfs_feed_info cascade;
drop table if exists gtfs_route_types cascade;
drop table if exists gtfs_directions cascade;
drop table if exists gtfs_pickup_dropoff_types cascade;
drop table if exists gtfs_payment_methods cascade;
drop table if exists gtfs_location_types cascade;
drop table if exists gtfs_transfer_types cascade;
drop table if exists service_combo_ids cascade;
drop table if exists service_combinations cascade;
-- PRAGMA foreign_keys = OFF;
begin;
create table gtfs_agency (
agency_id int 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
) AS SELECT * FROM CSVREAD('resources/agency.txt');
--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 int PRIMARY KEY,--PRIMARY KEY,
stop_code text,
stop_name text NOT NULL, --NOT NULL,
stop_lat double precision,
stop_lon double precision,
location_type int --FOREIGN KEY REFERENCES gtfs_location_types(location_type)
) AS SELECT * FROM CSVREAD('resources/stops.txt');
-- 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 varchar PRIMARY KEY,--PRIMARY KEY,
agency_id int , --REFERENCES gtfs_agency(agency_id),
route_short_name text DEFAULT '',
route_long_name text DEFAULT '',
route_type int , --REFERENCES gtfs_route_types(route_type),
FOREIGN KEY (agency_id) REFERENCES gtfs_agency(agency_id),
FOREIGN KEY (route_type) REFERENCES gtfs_route_types(route_type)
) AS SELECT * FROM CSVREAD('resources/routes.txt');
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 varchar 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
) AS SELECT * FROM CSVREAD('resources/calendar.txt');
create table gtfs_calendar_dates (
service_id varchar , --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 int --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 int 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 int, --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 int , --REFERENCES gtfs_fare_attributes(fare_id),
route_id int , --REFERENCES gtfs_routes(route_id),
origin_id int ,
destination_id int ,
contains_id int
-- unofficial features
,
service_id int, -- 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 int 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 varchar , --REFERENCES gtfs_routes(route_id),
service_id varchar , --REFERENCES gtfs_calendar(service_id),
trip_id int PRIMARY KEY,--PRIMARY KEY,
trip_headsign text,
direction_id int NOT NULL, --NOT NULL --REFERENCES gtfs_directions(direction_id),
shape_id int,
block_id int,
wheelchair_accessible int,
bikes_allowed int ,
FOREIGN KEY (route_id) REFERENCES gtfs_routes(route_id),
FOREIGN KEY (direction_id) REFERENCES gtfs_directions(direction_id)
) AS SELECT * FROM CSVREAD('resources/trips.txt');
create table gtfs_stop_times (
trip_id int , --REFERENCES gtfs_trips(trip_id),
arrival_time text, -- CHECK (arrival_time LIKE '__:__:__'),
departure_time text, -- CHECK (departure_time LIKE '__:__:__'),
stop_id int , --REFERENCES gtfs_stops(stop_id),
stop_sequence int NOT NULL, --NOT NULL,
pickup_type int , --REFERENCES gtfs_pickup_dropoff_types(type_id),
drop_off_type int , --REFERENCES gtfs_pickup_dropoff_types(type_id),
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 '__:__:__')
) AS SELECT * FROM CSVREAD('resources/stop_times.txt');
-- 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);
-- select AddGeometryColumn( 'gtfs_shapes', 'shape', #{WGS84_LATLONG_EPSG}, 'LINESTRING', 2 );
create table gtfs_frequencies (
trip_id int , --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 int, --REFERENCES gtfs_stops(stop_id)
to_stop_id int, --REFERENCES gtfs_stops(stop_id)
transfer_type int, --REFERENCES gtfs_transfer_types(transfer_type)
min_transfer_time int,
from_route_id int, --REFERENCES gtfs_routes(route_id)
to_route_id int, --REFERENCES gtfs_routes(route_id)
service_id int, --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;