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:

transitmap

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

{
        "agency_name":"Buenos Aires Transit",
        "agency_url":"http://www.buenosaires.gob.ar/subte",
        "agency_timezone":"America/Argentina/Buenos_Aires",
        "gtfs_mode":[
                [["MODE_ID","3"],0],
                [["MODE_ID","1"],1],
                [["MODE_ID","2"],2],
                [["MODE_ID","*"],3]
        ],
        "speed":[
                [["MODE_ID","3"],5.4],
                [["MODE_ID","1"],8.9],
                [["MODE_ID","2"],13.4],
                [["MODE_ID","*"],5.4]
        ],
        "stops":{
            "strategy":"picket",
            "spacing":[
                    [["MODE_ID","3"],500],
                    [["MODE_ID","1"],700],
                    [["MODE_ID","2"],1500],
                    [["MODE_ID","*"],400]
            ],
        },
        "route_id_prop_name":"ROUTE_ID",
        "route_name_prop_name":"ROUTE_NAME",
        "service_windows":[
                ["FRECHPM",6,9],
                ["FRECEPM",9,11],
                ["FRECALM",11,13],
                ["FRECEPT",13,15],
                ["FRECHPT",15,18]
        ],
        "start_date":"20140101",
        "end_date":"20150101",
        "exact":true
}

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/ba.zip

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.

screenshot1

screenshot2

screenshot3