I was wondering if anyone has had any success loading GTFS data to a mySQL database. I've looked all over the place for a good tutorial but I can't find anything that has been helpful.
I succeed in importing GTFS files into MySQL.
CREATE DATABASE gtfs
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
For instance, create the table stops
for stops.txt
,
-- stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,wheelchair_boarding
CREATE TABLE `stops` (
stop_id VARCHAR(255) NOT NULL PRIMARY KEY,
stop_code VARCHAR(255),
stop_name VARCHAR(255),
stop_lat DECIMAL(8,6),
stop_lon DECIMAL(8,6),
location_type INT(2),
parent_station VARCHAR(255),
wheelchair_boarding INT(2),
stop_desc VARCHAR(255),
zone_id VARCHAR(255)
);
For instance, load the local file stops.txt
into the table stops
,
LOAD DATA LOCAL INFILE 'stops.txt' INTO TABLE stops FIELDS TERMINATED BY ',' IGNORE 1 LINES;
The complete source code with an example is placed on GitHub ( here ). Make some slight changes for your purpose.
Have you tried this one :
https://code.google.com/p/gtfsdb/
The website says :
GTFS (General Transit Feed Specification) Database
Python code that will load GTFS data into a relational database, and Sql/Geo-Alchemy ORM bindings to the GTFS tables in the gtfsdb.
The gtfsdb project's focus is on making GTFS data available in a programmatic context for software developers. The need for the gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code to read GTFS data (whether that's an in-memory loader, a database loader, etc...); gtfsdb can hopefully reduce the need for such drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format.
I actually used the following link as a base and converted it to a script, worked like a charm
In my case, I created the table structures first.
Then load the data via the following command in mysql command console
load data local infile '/media/sf_Downloads/google_transit/stops.txt' into table stop fields terminated by ',' enclosed by '"' lines terminated by '\\n' ignore 1 rows;
This loads the stops.txt into stop table. ignore the first row (heading) in the stops.txt file.
'/media/...' is just the path to the file, where I extract the gtfs data.
I loaded the GTFS data into a SQLite database through the following commands:
Create a new SQLite Database named test.sqlite3
sqlite3 test.sqlite3
Set the mode to csv
sqlite> .mode csv
Import Each File into a corresponding table with import command .import FILE TABLE
sqlite> .import agency.txt agency
sqlite> .import calendar.txt calendar
...
sqlite> .import stops.txt stops
Now your database should be loaded
Hi looking for something similar and still not getting an easy way to do it. I am going to give a try GTFS to MySQl using Python
According to Google Developers , a GTFS feed is basically a zip file containing text files. You should be able to store it in your MySQL database using a BLOB type field. But this isn't recommended. You should store it as a file on your server's disk and then store the file's name/path into a regular text/varchar field in your database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.