Building GTFS files quickly with geom2gtfs

By Brandon Martin-Anderson 01 Jun 2014

What if you want to do rudamentary transit trip planning or perform transit level of service analysis, which usually requires a full GTFS feed, and all you have is a shapefile? We made a thing for that. It’s called geom2gtfs. Here’s how it works.

Say, hypothetically, you have a shapefile of the Buenos Aires transit system. The features in the shapefile have several useful fields, like “MODE_ID” (transit mode), “FRECHPM” (AM peak frequency), “FRECEPM” (AM off-peak frequency), “ROUTE_ID”, “ROUTE_NAME”, and so forth. It looks like this:


Make a file called config.json and fill it with this.

        "agency_name":"Buenos Aires Transit",

This configuration file assigns a mode according to the value of “MODE_ID”. Likewise, it specifies a speed (in meters per second) for different modes. geom2gtfs will generate stops for the GTFS file according to a strategy “picket”, which takes one argument “spacing”, which is an array of property filters corresponding to different spacings. For example if “MODE_ID” equals “3”, then the spacing is 500 meters. The feature properties containing values to be used as route ID and route name are identified, and the properties containing information about frequency at different times of day are named and associated with time ranges. The date span is given, and ‘exact’ is set to instruct geom2gtfs to generate an exact timetable, and not a frequency-based GTFS.

Then run geom2gtfs like this

java -jar ./build/libs/geom2gtfs.jar data/route_system_shape/Route\ System\ Buenos\ Aires\ 2012.shp ./config.json data/

Now you’ve got yourself a GTFS file for Buenos Aires! Put it in a folder with a PBF file of Buenos Aires streets and then compile them into a graph with OTP.

./otp --build /path/to/ba_gtfs/

Next, start up OpenTripPlanner

./otp --server --analyst -g ~/Documents/geom2gtfs/data/ba_gtfs/

Aim your browser at http://localhost:8080 and behold! Transit trip planning from a shapefile.