Visualizing Train Locations

GTFS-RT data is often abstracted and used to make calculations to be presented in forms like countdown clocks. On the Weekendest, we map where each individual train is going and its estimated time of arrivals by taking the data as is.

Sunny Ng
Good Service
3 min readFeb 11, 2020

--

The Weekendest displays train locations using GTFS-RT data from MTA New York City Transit

Maybe it’s just me, but whenever I’m waiting for a train, I always wonder where it is. No, I don’t mean, where as in “5 minutes away”, I mean where is it physically?

Visualizing GTFS-RT Trips

Anyone who has worked with GTFS-RT data—which drives much of the transit apps out there, know that the data consists of a bunch of trip updates (status of a transit vehicle that is currently being tracked) and stop time updates (when and where said transit vehicle is estimated to stop). To display a countdown clock for a station, you would have to aggregate all stop time updates that stop at the given station, calculate the difference in time between now and their estimated arrival time, and sort them in ascending order.

Similarly, the core functionality of the Weekendest—displaying real-time subway routing, is driven by aggregating trip updates and stop time updates to visualize where all trains will be stopping for the next hour or so. Unfortunately, the New York City Transit’s implementation of GTFS-RT doesn’t include vehicle locations. But if we don’t do any of the processing and aggregating of the data, we can try to figure out where each train is (or trip in GTFS-RT terms) by using its next closest stop time update to determine which station it is stopping next, and using Turf.js to calculate estimated current distance based on time and the compass direction of where each train is headed at.

The Weekendest showing where all the L trains are at the moment

What can this be used for?

Other than it being pretty cool, a real-life application of this is tracking where the next arriving train is currently at, and being able to track its movements as it is moving. You can click on any train location on the map or any next train arrival time at a station to bring you to the trip view. Every view in the Weekendest is linkable, so you can even send the tracking info to a friend to let them know you’re running late (and be able to prove it)!

View of a specific Far Rockaway-bound A train on the Weekendest, displaying its estimated arrival times at each upcoming station.

The Weekendest and goodservice.io are open-source projects to provide New York City subway riders detailed and up-to-date routing and statuses using public APIs. Contributions are welcome on GitHub. Feedback can be directed to @_blahblahblah or @goodservice_io on Twitter.

--

--