Estimating public transit "real-time" locations based on time-table data






Tõnis Kärdi
@tkardi
tonis.kardi@gmail.com

20.07.2017 - FOSS4G Europe
WHY?
Issues with train timetables ...
  • only future trips available
  • railway reconstruction - weekly changes
and no map
(with current location of trains)
When do I need to drive to the station then?
(got there some 30 min early)
What if there was an API that would return public transit locations?
(preferably in GeoJSON)
Address ranges to address points
(create n number of shifted points to the left, m to the right of street centerline)
Road sign data for routing
(got some really funny results, though...)
Power grid spatial data out of mast x, y coordinates
(power line centerlines, mast-to-mast protection zones, "wires", etc.)
... so why not simulate realtime public transit?
(from timetables to actual locations)
Enter GTFS*
(data supplied by the Estonian Road Administration)




* - The General Transit Feed Specification
https://developers.google.com/transit/gtfs/
  • routes - transit "lines" (e.g "bus number 5")
  • trips - a route in a given timeframe
  • calendar - weekly schedule for trips
  • stops - stop locations
  • stop_times - defines stops for a trip
  • shapes - vehicle paths for trips
  • ...
and others
(but we'll settle with these for the moment)
Calculating locations
(PostgreSQL + PostGIS)
length: ~ 4 km
Based on current time calculate fraction of time covered and st_lineinterpolatepoint
length: ~ 3.5 km, total time: 2 minutes
Cool!
(but with intermediate stops this bus might never be on time)
A to B: 1.8 km, B to A: 1.7 km
A to B: 30 secs, B to A: 90 secs
But how are passangers supposed to get on and off?
(add impedance to traveltime at stops)
Adding acceleration/deceleration to transit location calculation. See eoy#2 (in Estonian)
accelerate / decelarate: 8 secs, stop 3 + 3 secs
Red: interpolate whole trip. Blue: interpolate using stops. Green: interpolate using stops and impeded time
Current locations API
was: Django + Django REST framework | is currently: Flask
API
https://tkardi.ee/gtfs/current/locations/?format=json
Example dashboard
https://tkardi.github.io/eoy/example/current.html
Gotchas
Vehicles are always expected to move along the vector
(direction not checked)
calendar_dates not checked
(e.g. national holidays)
It's not really real-time
(e.g. traffic congestion, stops at intersections and traffic lights)
Where to next?
A bigger geographical area?
Past and future locations?
Support for use with QGIS TimeManager?
https://github.com/tkardi/eoy

@tkardi
tonis.kardi@gmail.com