Skip to content

Commit

Permalink
Merge branch 'master-stash'
Browse files Browse the repository at this point in the history
Conflicts:
	src/gtfs_tables.sql
  • Loading branch information
cbick committed Jun 22, 2012
2 parents 8b0e3e3 + 1aa4f45 commit e07a299
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
56 changes: 38 additions & 18 deletions src/gtfs_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ drop table gtfs_pickup_dropoff_types cascade;
drop table gtfs_payment_methods cascade;

drop table gtfs_location_types cascade;
drop table gtfs_wheelchair_boardings cascade;
drop table gtfs_transfer_types cascade;

drop table service_combo_ids cascade;
Expand All @@ -31,14 +32,12 @@ create table gtfs_agency (
agency_name text ,--NOT NULL,
agency_url text ,--NOT NULL,
agency_timezone text ,--NOT NULL,
agency_lang text
-- unofficial features
,
agency_lang text,
agency_phone text,
fare_url text
agency_fare_url text
);

--unoffical table, related to gtfs_stops(location_type)
--related to gtfs_stops(location_type)
create table gtfs_location_types (
location_type int PRIMARY KEY,
description text
Expand All @@ -51,14 +50,27 @@ insert into gtfs_location_types(location_type, description)
insert into gtfs_location_types(location_type, description)
values (2,'station entrance');

--related to gtf_stops(wheelchair_boarding)
create table gtfs_wheelchair_boardings (
wheelchair_boarding int PRIMARY KEY,
description text
);

insert into gtfs_wheelchair_boardings(wheelchair_boarding, description)
values (0, 'No accessibility information available for the stop');
insert into gtfs_wheelchair_boardings(wheelchair_boarding, description)
values (1, 'At least some vehicles at this stop can be boarded by a rider in a wheelchair');
insert into gtfs_wheelchair_boardings(wheelchair_boarding, description)
values (2, 'Wheelchair boarding is not possible at this stop');


create table gtfs_stops (
stop_id text ,--PRIMARY KEY,
stop_name text , --NOT NULL,
stop_desc text,
stop_lat double precision,
stop_lon double precision,
zone_id int,
zone_id text,
stop_url text,
stop_code text,

Expand All @@ -73,7 +85,12 @@ create table gtfs_stops (

location_type int, --FOREIGN KEY REFERENCES gtfs_location_types(location_type)
parent_station text, --FOREIGN KEY REFERENCES gtfs_stops(stop_id)
stop_timezone text
stop_timezone text,
wheelchair_boarding int --FOREIGN KEY REFERENCES gtfs_wheelchair_boardings(wheelchair_boarding)
-- Unofficial fields
,
direction text,
position text
);

-- select AddGeometryColumn( 'gtfs_stops', 'location', #{WGS84_LATLONG_EPSG}, 'POINT', 2 );
Expand Down Expand Up @@ -175,16 +192,18 @@ create table gtfs_fare_attributes (
currency_type text , --NOT NULL,
payment_method int , --REFERENCES gtfs_payment_methods,
transfers int,
transfer_duration int,
transfer_duration int
-- unofficial features
,
agency_id text --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
origin_id text ,
destination_id text ,
contains_id text
-- unofficial features
,
service_id text -- REFERENCES gtfs_calendar(service_id) ?
Expand All @@ -205,10 +224,10 @@ create table gtfs_trips (
trip_headsign text,
direction_id int , --REFERENCES gtfs_directions(direction_id),
block_id text,
shape_id text
shape_id text,
trip_short_name text,
-- unofficial features
,
trip_short_name text
trip_type text
);

create table gtfs_stop_times (
Expand Down Expand Up @@ -243,6 +262,7 @@ create table gtfs_frequencies (
start_time text , --NOT NULL,
end_time text , --NOT NULL,
headway_secs int , --NOT NULL
exact_times int,
start_time_seconds int,
end_time_seconds int
);
Expand All @@ -251,9 +271,6 @@ create table gtfs_frequencies (



-- unofficial tables


create table gtfs_transfer_types (
transfer_type int PRIMARY KEY,
description text
Expand All @@ -274,6 +291,7 @@ create table gtfs_transfers (
to_stop_id text, --REFERENCES gtfs_stops(stop_id)
transfer_type int, --REFERENCES gtfs_transfer_types(transfer_type)
min_transfer_time int,
-- Unofficial fields
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) ?
Expand All @@ -285,7 +303,9 @@ create table gtfs_feed_info (
feed_publisher_url text,
feed_timezone text,
feed_lang text,
feed_version text
feed_version text,
feed_start_date text,
feed_end_date text
);


Expand Down
22 changes: 22 additions & 0 deletions src/import_gtfs_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ def handleCols(self,columns):
def handleVals(self,row,header):
return row

class AgencyHandler(SpecialHandler):
def handleCols(self, columns):
# Column name was originally proposed as fare_url
if 'fare_url' in columns:
colIdx = columns.index('fare_url');
columns[colIdx] = 'agency_fare_url';

if not 'agency_id' in columns:
self.appendId = True
self.ix = 0
columns = columns + ['agency_id',]
else:
self.appendId = False

return columns

def handleVals(self, row, cols):
if self.appendId:
row.append(str(self.ix))
self.ix += 1
return row

class TripsHandler(SpecialHandler):
def handleCols(self,columns):
Expand Down Expand Up @@ -172,6 +193,7 @@ def import_file(fname, tablename, handler, COPY=True):
];

handlers = dict.fromkeys(fnames);
handlers['agency'] = AgencyHandler();
handlers['stop_times'] = StopTimesHandler();
handlers['trips'] = TripsHandler();
handlers['frequencies'] = FrequenciesHandler();
Expand Down

0 comments on commit e07a299

Please sign in to comment.