Felix Delattre

osm2gtfs, extendable for any city

Convert data from OpenStreetMap into GTFS


osm2gtfs announcement

The Nicaraguan OpenStreetMap Community started some years ago a public transport project to create the first proper bus map of a Central American city. Once the data has been collected in a collective crowd-sourcing process directly on OpenStreetMap, a paper map has been created. In a next step this data should 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 in most public transport routing solutions.

At this point, checking different options to convert OpenStreetMap data into GTFS - unfortunately none was satisfying. Within this desk study I also stumbled over 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 Brasil. It grabbed data from OpenStreetMap, parsed online information about schedule 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.

Due to the implemented changes it allowed at a later stage, more initiatives to join the effort: Accra Mobility, a project by the French Development Agency, directly through our partner initiative JungleBus, who extended the 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 collaborated 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 to convert 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 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 through extending the code. For any city and schedule format the script can be easily extended, see the developer documentation for more information.