OSM2GTFS for Accra - user manual

From OpenStreetMap Wiki
Jump to navigation Jump to search

OSM2GTFS for Accra - User's manual

During AccraMobile3, the Jungle Bus team worked on a the creation of a GTFS file, using OSM2GTFS tool.

The file is freely available here : https://github.com/AFDLab4Dev/AccraMobility/tree/master/GTFS

This page explains how to update this file.


The purpose of OSM2GTFS is to provide an easy to use tool to generate transit data from OpenStreetMap in a worldwide standard format called GTFS.

The generated GTFS data feed can then be used in a large collection of tools, such as TransitApp or navitia.io, to :

  • provide journey computation
  • provide next departures boards
  • enable transit network analyses to look for improvements
  • provide access informations to improve marketing campaigns of shops or retail companies
  • etc

How to use


This manual is assuming that the user is running a Ubuntu Distribution with a fully functional python2.7 environment and git package already installed.

Installing the software

1. Clone the repository to your local environment

git clone git@github.com:grote/osm2gtfs.git

2. Install the dependencies

sudo pip install -e .

The python-overpy and transitfeed python packages will be installed.

Running the Accra GTFS feed generation

1. Change the current directory to the osm2gtfs directory (`cd ~/osm2gtfs` if you used the previous path)

2. Review the config file (osm2gtfs/creators/gh_accra/config.json). Check and change if needed the start_date and end_date:

  • the "end_date" should be at least 3 months from now
  • the duration between "start_date" & "end_date" should not exceed one year

3. Delete the cache files if any, to update information from OpenStreetMap.

The files are located in the `data` directory (`~/osm2gtfs/data/`) and the files are named `stops-accra.pkl` and `routes-accra.pkl`. For example, you can run the following command : `rm data/*.pkl`

4. Run the program with only the accra configuration file to generate the GTFS feed : `osm2gtfs -c ./osm2gtfs/creators/gh_accra/config.json`

While running, osm2gtfs is making a lot of call to an external API called Overpass (http://overpass-turbo.eu/) to collect OSM data and record them locally in the cache files previously deleted.

Sometimes, the load of the Overpass server is too high, and replies with an error. In those cases, simply run again the program, osm2gtfs will resume the data collection from the last error.

The GTFS file is generated in the ./data folder with the file name specified in the Accra config file. For exemple : `~/data/gh-accra.zip`

5. Check the generated GTFS :

In the ZIP file, you should find 9 files, and specifically :

  • a "feed_info.txt" that contains the validity of the feed.
  • a "routes.txt" file containing more than 270 rows (one row for each public transport line in Accra)
  • a "stops.txt" file containing more than 4000 stops
  • a non empty "stop_times.txt"

Publishing the generated data

1. Make sure the GTFS feed is named "GTFS_Accra.zip" (and rename it if not)

2. Open in a web browser the Digital Transport 4 Africa repository : https://git.digitaltransport4africa.org/places/accra/tree/master/GTFS

3. Upload the GTFS_Accra.zip file

4. In the commit title form, set the message "Update of Accra GTFS - 20171231" changing the date accordingly to the current day (in the format YYYY MM DD), select "push on master" and click on the "commit" button

And what if ...

What if the validity of the feed less than 3 months away ?

Open the "osm2gtfs/creators/gh_accra/config.json" file and change the value associated to the "end_date" property of the "feed_info" object.

What if the program is not properly running ?

If you can't make the program run properly, open an issue in GitHub in the project https://github.com/grote/osm2gtfs/ and try to describe the problem and the encountered error.