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.

  1. Download the GTFS data you want. Find data from agencies around the world (although not many from Europe) on GTFS Data Exchange.
  2. Import into ArcGIS the shapes.txt file using Tools>Add XY Data. Specify Y=lat and X=lon
  3. Using ET GeoWizards GIS tools, in the Convert tab, convert the points shapefile to polyline.
  4. Select the shapes layer in the wizard, then create a destination file. Click Next.
  5. Select the “shape_id” field
  6. Click the checkbox next to Order and select the field “shape_pt_sequence” and click Finish.
  7. Depending on the number of records (the CTA has 466,000 shapes), it may take a while.
  8. The new shapefile will be added to your Table of Contents and appear in your map.
  9. 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.
  10. Export the text files as DBF files so that ArcGIS operates on them better. Then remove the text files from the Table of Contents.
  11. (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.
  12. Join routes and trips based on the field “route_id” – export as trips_routes.dbf
  13. 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″
  14. Join routes_trips with shapes into routes_poly based on the field “shape_id” (and “shape_id2″)
  15. 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
  16. 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 points to polylines (result, 4 of 4)Converting points to polylines (3 of 4)Converting points to polylines (2 of 4)Converting points to polylines (1 of 4)

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.)
Tagged with:
 
  • http://railzone.nl Daniel Sparing

    O thanks for this, this is gonna be really useful for me.

    You guys are lucky to have public GTFS data from the operators.

    • http://www.stevevance.net/planning Steven Vance

      I’m sure that Google’s European offices are working on convincing the transit operators there.

      Do you know what the barriers are or what the resistance is based on?

      As far as international operators, it looks like several in Australia and New Zealand provide GTFS data publicly.

      • http://railzone.nl Daniel Sparing

        Yeah, there are Google Transit implementations in Europe: whole Switzerland, whole Denmark and since December Dutch trains and Amsterdam urban public transport:
        http://railzone.nl/2010/12/google-transit-in-the-netherlands/

        But there is no culture (yet) to give away the data itself publicly here.

        Partly this is because operators do not want to share realized timetable data as then it is too easy to judge their performance — but GTFS is just the published timetable data, so that is because of reluctance, or the idea (with which I don’t always agree) to control the mediums where timetable information is shown.

      • John

        Hi Steve,
        thank you for sharing this great tool. I was able to create the polyline from
        shapes. However, the Dissolve/Generalization did not create the line file. I
        tried a few times and never succeeded. I appreciate your help.  — John Jiang ([email protected])

        • http://www.stevevance.net/ Steven Vance

          Hi John, sorry for the late reply. Were you able to succeed in converting it?

  • Pingback: www

  • Pingback: fiverr is my niche Keyword.

  • Pingback: Foil Bags

  • Pingback: Know more about Buy k2

  • Pingback: clairvoyant phone readings

  • Pingback: clairvoyants

  • Pingback: Putting transit GIS data to use « Spatiality

  • Ion

    Do you know of any opensource softwares (QuantumGIS, etc) that can do the conversion? I have no access to ArcGIS. Thanks.

    • http://www.stevevance.net/ Steven Vance

      This can likely be done in QGIS, but I haven’t verified it. I haven’t done any work with GTFS since writing this article.

      • Joel Davis

        I think i’ve figured out how to do it, though it’s incredibly tedious. The shapes.txt file needs to be converted to a CSV and then imported as a tab delimited text layer. From there use the attribute layer to seperae each route into new layers and use the points2one plugin to create lines.

        • http://www.stevevance.net/ Steven Vance

          Since GTFS is a well-known specification, I’m sure a Python plugin for QGIS could be written that converts GTFS data into shapefiles in a few seconds. A second script could be written that pulls in the data from the transit providers around the world to convert them and host them for the public.