Felix Delattre

osm2gtfs, extendable for any city

Convert data from OpenStreetMap into GTFS


osm2gtfs announcement

Some years ago, the Nicaraguan OpenStreetMap Community started a public transport project to create the first proper bus map of a Central American city. Once the data had been collected in a collective crowd-sourcing process directly on OpenStreetMap, a paper map was created. As a next step, this data was to be made available in different applications. The most obvious and best path was to rely on the common format GTFS, which can be easily integrated into most public transport routing solutions.

At this point, I checked different options to convert OpenStreetMap data into GTFS - unfortunately, none was satisfying. Within this desk study I also stumbled upon the Python script osm2gtfs, by Torsten Grote, the creator of the great Free and Open Source public transport application Transportr. This script was targeted to only work for Florianopolis in Brazil. It grabbed data from OpenStreetMap, parsed online schedule information from the bus operators’ website and created a GTFS out of it.

osm2gtfs was not ready to be used for any other city, but it seemed to be the best option to develop further: it relied on suitable libraries like transitfeed and was written in Python, which I think was a good choice. So I teamed up with the maintainer and Jaime from the Costa Rican OpenStreetMap community to evolve osm2gtfs into a useful tool for many cities. Together, we essentially rewrote the initial script into a new structure, which is flexibly extendable for other cities and different sources of schedule information, and introduced a general standard process that could work for many cities without programmatically extending the software.

At a later stage, the implemented changes allowed more initiatives to join the effort: Accra Mobility, a project by the French Development Agency, directly through our partner initiative JungleBus, which extended osm2gtfs to produce the GTFS for the capital and largest city of Ghana.

Also in Nicaragua, in the northern city of Estelí, international weltwärts volunteers took on the task of mapping the public transport system there. They made it happen, and worked extensively with the osm2gtfs software package.

osm2gtfs is a community-based initiative for the development of a versatile tool to convert OpenStreetMap public transport data, combine it with external schedule information, and create a General Transit Feed (GTFS). The software has been developed by community members from Brazil, Nicaragua, Costa Rica and France. osm2gtfs can now be used without any programming skills when using our defined input format. And, of course, with programming skills it is always flexibly extendable to support any other city’s particularities and sources for schedules.

If you are interested in converting OpenStreetMap data into GTFS, check out the documentation and feel free to communicate over the project’s issue queue or contact us directly. Of course, any contribution is highly appreciated.

How does it work?

The script retrieves current data about public transport networks directly from OpenStreetMap via the Overpass API. It stores the data in Python objects and caches it on disk for efficient re-use. Then the data is combined with another source of schedule (time) information in order to create a GTFS file using the transitfeed library.

For every new city a new configuration file needs to be created. Additionally, schedule information should be provided. By default, the schedule information is expected to be provided in a certain format. However, other formats are supported by extending the code. For any city and schedule format the script can be easily extended; see the developer documentation for more information.