Skip to content

Instantly share code, notes, and snippets.

@dsamojlenko
Last active March 6, 2016 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsamojlenko/4463157 to your computer and use it in GitHub Desktop.
Save dsamojlenko/4463157 to your computer and use it in GitHub Desktop.
Import GTFS data to SQLite (need to remove header row after import). These commands should be entered in a SQLite command-line shell.
Create a database in the same directory as the GTFS files by typing:
shell> sqlite3 gtfs_db
The following commands should be executed in the SQLite shell:
CREATE TABLE agency (agency_name TEXT, agency_url TEXT, agency_timezone TEXT, agency_lang TEXT);
CREATE TABLE stops (stop_id TEXT, stop_code INTEGER, stop_name TEXT, stop_desc TEXT, stop_lat REAL, stop_lon REAL, stop_street TEXT, stop_city TEXT, stop_region TEXT, stop_postcode TEXT, stop_country TEXT, zone_id INTEGER);
CREATE TABLE routes (route_id TEXT,route_short_name TEXT,route_long_name TEXT,route_desc TEXT,route_type INTEGER);
CREATE TABLE trips (route_id TEXT,service_id STRING,trip_id STRING,trip_headsign TEXT,block_id INTEGER);
CREATE TABLE stop_times (trip_id STRING,arrival_time TEXT,departure_time TEXT,stop_id TEXT,stop_sequence INTEGER,pickup_type INTEGER,drop_off_type INTEGER);
CREATE TABLE calendar (service_id STRING,monday INTEGER,tuesday INTEGER,wednesday INTEGER,thursday INTEGER,friday INTEGER,saturday INTEGER,sunday INTEGER,start_date TEXT,end_date TEXT);
CREATE TABLE calendar_dates (service_id STRING,date TEXT,exception_type INTEGER);
.separator ,
.import calendar.txt calendar
.import agency.txt agency
.import calendar_dates.txt calendar_dates
.import routes.txt routes
.import stop_times.txt stop_times
.import stops.txt stops
.import trips.txt trips
CREATE INDEX stops_stop_id ON stops(stop_id ASC);
CREATE INDEX stops_stop_code ON stops(stop_code ASC);
CREATE INDEX routes_route_id ON routes(route_id ASC);
CREATE INDEX trips_route_id ON trips(route_id ASC);
CREATE INDEX trips_service_id ON trips(service_id ASC);
CREATE INDEX trips_trip_id ON trips(trip_id ASC);
CREATE INDEX stop_times_trip_id ON stop_times(trip_id ASC);
CREATE INDEX stop_times_stop_id ON stop_times(stop_id ASC);
CREATE INDEX calendar_service_id ON calendar(service_id ASC);
CREATE INDEX calendar_dates_service_id ON calendar_dates(service_id ASC);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment