This tutorial will teach how you to convert any transit agency’s General Transit Feed Specification (GTFS) data into ESRI ArcGIS-compatible shapefiles (.shp), KML, or XML. This is simple to do because GTFS data is essentially a collection of CSV (comma separated values) text files (really, really large text files).
Note: I don’t know how to do the reverse, converting shapefiles or other geodata into GTFS data. I’m not sure if this is possible and I’m still investigating it. If you have tips, let me know.
Converting GTFS to GIS shapefiles
Instructions require the use of ArcGIS (Windows only) and a free plugin called ET GeoWizards GIS for any version of ArcGIS. I do not have instructions for Mac users at this time.
I wrote these instructions while converting the Chicago Transit Authority’s GTFS files into shapefiles based on a reader’s request. “Field names” are quoted and layer names are italicized.
- Download the GTFS data you want. Find data from agencies around the world (although not many from Europe) on GTFS Data Exchange.
- Import into ArcGIS the shapes.txt file using Tools>Add XY Data. Specify Y=lat and X=lon
- Using ET GeoWizards GIS tools, in the Convert tab, convert the points shapefile to polyline.
- Select the shapes layer in the wizard, then create a destination file. Click Next.
- Select the “shape_id” field
- Click the checkbox next to Order and select the field “shape_pt_sequence” and click Finish.
- Depending on the number of records (the CTA has 466,000 shapes), it may take a while.
- The new shapefile will be added to your Table of Contents and appear in your map.
- Import the trips.txt and routes.txt files. Inspect them for any NULL values in the “route_id” field. You will be using this field to join the routes and trips table. It may be a case that ArcGIS imported them incorrectly; the text files will show the correct data. If NULL values appear, follow steps 10 and 11 and continue. If not, follow steps 10 and 12 and continue. This happens because ArcGIS inspected some of the data and determined they were integers and ignored text. However, this is not the case.
- Export the text files as DBF files so that ArcGIS operates on them better. Then remove the text files from the Table of Contents.
- (Only if NULL values appear) Go into editing mode and fix the NULL values you noticed in step 9. You may have to make a new column with a more forgiving data type (string) and then copy the “route_id” column into the new column. Then continue to step 12.
- Join routes and trips based on the field “route_id” – export as trips_routes.dbf
- Add a new column to shapes.shp called “shape_id2″, with data type double 18, 11. This is so we can perform step 14. Use the field calculator to copy the values from “shape_id” (also known as ET_ID) to “shape_id2″
- Join routes_trips with shapes into routes_poly based on the field “shape_id” (and “shape_id2″)
- Dissolve routes_poly on “route_id.” Make sure all selections are cleared.Â Use statistics/summary fields: “route_long,” “route_url.” Save as routes_diss.shp
- Inspect the new shapefile to ensure it was created correctly. You may notice that some bus routes don’t have names. Since these routes are well documented on the CTA website, I’m not going to fill in their names.
Click on the screenshot to see various steps in the tutorials.
Converting GTFS to KML
After you have it in shapefile form, converting to KML is easy – follow these instructions for using QGIS. Or if you want to skip the shapefile-creation process (quite involved!), you can use KMLWriter, a Python script. Also, I think the latest version of ArcGIS has built-in KML exporting.
Converting GTFS to XML
If you want to convert the GTFS data (which are essentially comma-separated value – CSV – files) to XML, that’s easier and you can avoid using GIS programs.
- First try Mr. Data Converter (very user friendly).
- If that doesn’t work, try this websiteÂ form on Creativyst. I tested it by converting the CTA’s smallest GTFS table, frequencies.txt, and it worked properly. However, it has a data size limit. (User friendly.)
- Next try csv2xml, a command line tool. (Not user friendly.)
- You can also use Microsoft Excel, but read these tips and caveats first. (I haven’t found a Microsoft application I like or think is user friendly.)
About Steven Can Plan
I started this blog in 2007 as the writing assignment for an introductory urban planning class at UIC. It's about cities (mainly Chicago), GIS oftentimes, and transportation (mainly bicycling). Learn more about me, Steven Vance. I also write for Streetsblog Chicago.
Steven Can Plan is hosted on Dreamhost.
Chicago Bike Map App
The Chicago Bike Map app is a bike and street map stored entirely in your iOS device – no data connection required. The map is designed to look much like the City of Chicago's official printed and online bike map. The app works on iPhone, iPod touch, and iPad.
Highly Recommended Bike Products
So far my longest trip was 40 miles on this saddle. It molds to your butt like Birkenstock sandals mold to your feet. The springs make the bike ride a little more comfortable and more fun (weird, because you bounce up and down on them). It also looks gorgeous. Comes in 3 colors - I got black.
These folding locks are lighter weight and more versatile than an equally strong u-lock.
I've used this pannier to carry groceries, books, my laptop, clothing, anything. I like it because it's stylish (but also "normal" looking at the same time), stands up on its own, is extremely durable, and has the most universal attachment system: two hooks.
Sustainable Transportation Planning: Tools for Creating Vibrant, Healthy, and Resilient Communities (Wiley Series in Sustainable Design) by Jeffrey Tumlin
I was sent a review copy. I'm really excited to open it up and start reading because I've been disappointed with textbooks in the past that don't focus on bicycle and pedestrian planning.
The Death and Life of Great American Cities (50th Anniversary Edition) (Modern Library) by Jane Jacobs
Traffic: Why We Drive the Way We Do (and What It Says About Us) by Tom Vanderbilt
As someone who doesn't like driving, but believes that cars can be efficient in moving groups of people and goods, this is my favorite book.
Instant City: Life and Death in Karachi by Steve Inskeep
I reviewed this book that the publisher sent to me.