This guide provides instructions on how to ingest GTFS (General Transit Feed Specification) data into the Universal Transit Platform.
- Introduction
- Prerequisites
- GTFS Data Structure
- Steps to Ingest Data
- Troubleshooting
- Frequently Asked Questions
- Contact
GTFS is a standard format for public transportation schedules and associated geographic information. By ingesting GTFS data, we populate the database with up-to-date transit information.
- Ensure that the project is set up according to the Getting Started Guide.
- The virtual environment is activated.
- Dependencies are installed (
pip install -r requirements.txt).
GTFS data typically comes as a ZIP file containing several text files, such as:
agency.txtstops.txtroutes.txttrips.txtstop_times.txtcalendar.txtcalendar_dates.txtfare_attributes.txtfare_rules.txtshapes.txtfeed_info.txt
- Option 1: Download GTFS data from transit agencies' websites.
- Option 2: Use repositories like TransitFeeds to find GTFS data.
-
Create a directory named
gtfsinside thedatafolder if it doesn't exist:mkdir -p data/gtfs
-
Extract the contents of the GTFS ZIP file into the
data/gtfsdirectory. Ensure that all the.txtfiles are directly insidedata/gtfs.
From the project root directory, run:
python -m src.ingest_gtfs- This script will read the GTFS files and populate the database accordingly.
- It may take a few minutes depending on the size of the GTFS data.
- Check that the
transit.dbfile has been created or updated. - Use the API endpoints to retrieve data and ensure it's correctly loaded.
For example, run the application:
uvicorn src.main:app --reloadThen navigate to http://localhost:8000/agencies to see if agency data is available.
- File Not Found Error: Ensure that the GTFS
.txtfiles are correctly placed in thedata/gtfsdirectory. - Database Errors: Delete the existing
transit.dbfile and rerun the ingestion script to start fresh. - Import Errors: Make sure you're running the script with the
-mflag and from the project root directory.
A: Yes, you can. Place each agency's GTFS data in separate folders within data/gtfs and modify the ingestion script to process multiple directories.
A: It's recommended to update the data whenever a new GTFS feed is released by the transit agency, usually every few months.
A: The ingestion script may need to be updated to handle additional GTFS files or fields.
If you encounter issues or have questions not covered in this guide, please:
- Open an issue on GitHub.
- Contact us at universaltransitplatform@gmail.com.
Note:
- Replace
yourusernamewith your actual GitHub username. - Ensure that you have the necessary permissions to use the GTFS data from the transit agency.
- Be aware of any licensing or data usage restrictions.