Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL - Load GTFS Data

Tags:

php

mysql

gtfs

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.

like image 687
Mikerizzo Avatar asked Jun 04 '26 08:06

Mikerizzo


1 Answers

I succeed in importing GTFS files into MySQL.

Step 1: Create a database

CREATE DATABASE gtfs
    DEFAULT CHARACTER SET utf8
    DEFAULT COLLATE utf8_general_ci;

Step 2: Create tables

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)
);

Step 3: Load local data

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.

like image 55
SparkAndShine Avatar answered Jun 07 '26 10:06

SparkAndShine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!