dadecasdev

TrenVivo

Spain's rail network in real time, on a map and in 3D, built entirely on public data.

PythonMapLibre GLthree.jsGTFS / GTFS-RTOpenStreetMapJavaScript

The problem

Renfe publishes the position and delay of its trains, but in raw form: separate feeds for long-distance, commuter, GTFS-RT updates and timetables, with no speed, no track each train is running on and no context. Adif, which manages the infrastructure and signalling, does not publish the state of the network openly. The question behind the project was how far you can get with public data alone, without access to Renfe's or Adif's internal systems.

The solution

A dependency-free Python server that combines Renfe's live feeds with the day's GTFS timetables and the OpenStreetMap rail network: maximum speed, gauge and signalling system (LZB, ERTMS/ETCS, ASFA) for every section. It computes each train's speed from successive positions, snaps it to its real track and detects anomalies: trains stopped between stations, delays that spike or abnormally slow running, grouping those that coincide on the same section. It does not try to replace or improve Renfe's or Adif's systems, which work with data that is not public: it is a demonstration of what open data already allows and, by extension, of what a tool like this could achieve with the right access and resources.

What it includes

  • Around 400 long-distance, regional and commuter trains refreshed every 15 seconds
  • Computed speed, track speed limit and signalling system of the section each train is running on
  • 3D view: the camera follows the train along the real track over IGN aerial imagery, with a model of its series (Velaro, Talgo, Civia…) car by car
  • Itinerary with expected times and cancelled stops, plus a departures and arrivals board for every station
  • Anomaly detection per train and per section, railway signals in 3D and approximate kilometre point
  • Mobile version with a draggable sheet, obfuscated production code and an API restricted to the site itself

Outcome

Public application at trenvivo.onrender.com, running on a free hosting plan. It combines six open sources (Renfe feeds, GTFS, GTFS-RT, OpenStreetMap, IGN aerial imagery and CARTO base maps), 33,542 track sections with their signalling and 2,742 signals. Anomalies are inferred from train behaviour, not official incidents, and the app says so: with access to Adif's data, the same architecture could show the real state of the signalling.

Working on a similar challenge?

Tell me about your project ↗