Philadelphia bus mapping using open data

Screen Shot 2014-03-01 at 12.51.57 PM
Philly Buses by Neighborhood Map
Philly Buses By Neighborhood Map

In my previous post I talked about an app I worked on at a Hackathon that visualizes the accessibility of Philadelphia stations and services around them.  After seeing how much open transit data is out there and being inspired by other open data mapping apps, including those by Chris Whong (in particular the Baltimore City Charm Circulator visualization he worked on with a team at Reinvent Transit), I thought it would be cool to see bus routes, positions and patterns by Philly neighborhood and integrate this into the ‘Unlock Philadelphia’ website.

Google transit searches go point to point and assume you know your exact departure and destination locations.

SEPTA’s website lets you see bus routes and positions, but for a single route that you already know by number.

How about if you’re new to an area, don’t have a car and just want to know where you can get to on the transit system and see where all the buses are? Or just interested in all the places it’s possible to get to easily without getting the car out? In other words, add a bit of serendipity to your search.

Digging through all the maps and timetables is possible, but awkward. Using open data and mapping techniques that allow users to interact with a visualization provides a much better experience.

To realize the concept, I spent a lot of time grouping bus routes by the neighborhoods they pass through.  SEPTA’s KML data gives all the coordinates for bus routes. To make make it easy to distinguish one route from another I adjusted the colors of the routes with a bit of help from ColorBrewer (they were all blue to begin with).

A REST API is available from SETPA that provides data for every bus including lat/long, route id, bus id, destination, direction. It’s interesting to see how often the data sent by the buses is inaccurate: a number of times I’ve seen buses moving in the opposite direction from the direction they say they’re moving in. The positions of the buses is updated on average every three minutes based on a signal sent to a cetral SEPTA server by a GPS device in the bus.  The bus data is queried using the ‘bus/trolley locations’ endpoint on this page:-

The app/visualization is here: it’s hosted on Heroku and uses Ruby (a simple REST API using Sinatra), Javascript/JQuery, Google Maps and MongoDB.

Bus Movements and Bunching
Bus Movements and Bunching

An extension to this idea is use the bus data to visualize ‘bus bunching'; we’ve all had that experience of waiting for a bus and then 3 come at once.  I wrote a script to collect a day’s worth of bus positions and then mapping/animating the data to see if patterns emerge.  The work on this is in its infancy; the visualization needs improving to give a better sense of where buses are bunching. D3 rather than LeafletJS could be a good choice for this. It would be awesome to use the proximity of buses traveling in the same direction on the same route to gather statistics and visualize  in an improved and enhanced map. Any ideas and contributions welcome! The early prototype is here: .  I’ll blog more about this soon.

Leave a Reply

Your email address will not be published. Required fields are marked *