How deep is the Barcelona metro

Barcelona on rails, the rail network in Chronotopia, draws every railway of the metropolitan area from 1848 to around 2040, and it draws the underground in real 3D: each tunnel at its depth, each platform at its level. You can open it at chronotopia.vedratic.com/en/barcelona-rails/. The track geometry comes from OpenStreetMap, which knows where a tunnel runs but not how far down.

That second number is rarely published. There are no public longitudinal profiles for the metro, FGC or Rodalies, and the figures that exist are scattered across press notes, project summaries and enthusiasts’ pages. This article is about scripts/rails-depth.py, which turns those few figures and a set of rules into a profile for every tunnel, and about how much of the result is sourced: 4.0% of the profile points. The years each tunnel exists come from a separate step, described in dating a rail network from 1848 to 2040.

Almost nothing is published

The research file data/station-depths.json has 190 rows, one per line at each station, for 160 stations. Each has a confidence: H for a project drawing or an official figure, M for a figure in metres from a secondary source, L for an estimate by rule. There are 11 H, 30 M and 149 L.

Three of the H rows are at Espanya. The Generalitat’s construction project TM-11016, for the evacuation and accessibility works there, gives platform heights above sea level against a street at 26.80 m: FGC at 15.17 m, the L1 at 14.83 m and the L3 at 6.94 m. That puts the platforms 11.6, 12.0 and 19.9 m below the street. The other eight H rows have one source each: Generalitat notes for Roquetes (56 m) and Trinitat Nova (30 m) on the L3, an Infraestructures.cat note for the three stations of the L8 extension (45 to 50 m), and, marked H in the file although they are secondary sources, Trenscat pages for Plaça de Sants (12.5 m) and Can Zam (18 m) and Catalan Wikipedia for Ferran (4.83 m). No other old interchange has a primary document for its order.

Most M rows are on the newer, deeper lines. El Coll | La Teixonera on the L5 is 74 m down, the deepest station in service according to a Generalitat note of 2010. For the older metro lines under the streets, and for every Rodalies and FGC station except Espanya, there is no figure at all. Those rows are estimated from the construction method: 9 to 14 m for a metro platform in a cut-and-cover box, 12 to 16 m for FGC.

A method for every tunnel

The method decides the depth, the minimum cover and the shape of a tunnel, so the script first gives one to each tunnel stretch (the depth summary of network.json counts 432), from the 33 rows of data/methods.json:

A tunnel the research doesn’t mention is mined if the ground rises 25 m or more above its lower portal, cut-and-cover if not. Another rule follows from the cover. A bore needs at least 1.5 diameters of soil above it, so in the 11.96 m tube of the L9 the upper rail is at least 22.9 m down. An L9 or L10 stretch next to a platform shallower than 21.8 m becomes cut-and-cover, which is what TYPSA and Ingemey describe at the ends of the line.

The result is in data/depth-methods.json, which lists 424 stretches: 32 have an H method (the L9 bores, from the Generalitat’s 2008 project summary, and seven L9/L10 stretches in the open or between diaphragm walls, from Ingemey and TYPSA), 180 M and 212 L. For 118 metro stretches the M means “cut-and-cover under the road”, which methods.json calls general knowledge without a specific source.

From two platforms to a profile

The profile is the height of the rail along the tunnel, and it starts at the stations: the ground from a 20 m terrain raster, minus the platform depth, minus 1.1 m from the platform to the rail. A published row is a hard point measured from the ground right there. An estimated row is soft, and its ground is averaged over ±100 m, or the bumps of the raster would make a line zig-zag.

Between stations the script first solves each chain of tunnel stretches as one line on its own, in three steps:

  1. A target: straight between platforms, level for 40 m either side of each one.
  2. An envelope: the highest profile allowed by the minimum cover of the method and the maximum gradient, which is 4% for the metro, 4.5% for FGC, 2% for Rodalies and 3% for high speed.
  3. The profile: the lower of the two at every point.

The gradient limit is a function that sweeps the line both ways and never lets a point sit higher than its neighbour plus the allowed climb:

def lipschitz_min(U, slope, step):
    """Highest profile under U whose gradient does not pass `slope` (array per sample) in any direction."""
    z = U.copy()
    for i in range(1, len(z)):
        z[i] = min(z[i], z[i - 1] + slope[i] * step)
    for i in range(len(z) - 2, -1, -1):
        z[i] = min(z[i], z[i + 1] + slope[i] * step)
    return z

So the gradient only changes where a platform, a portal or the cover forces it to. Each vertex gets a point, marked approx unless it sits on a published platform or at a portal. network.json records 9,797 profile points, 389 of them sourced: the 4.0%.

That is the profile of a chain on its own. What the chains share is then solved together, as one linear programme over every sample of every chain (scripts/rails_depth_lp.py). It keeps each tunnel as close as it can to its own profile, lets the platform with less information move before the one with more, keeps a platform with a published depth within 2 m of it, and puts the upper track of every crossing at least the separation above the lower. What the limits make impossible is not forced: it goes to unresolved in data/depth-checks.json, 60 places in the current run (49 platforms and 11 crossings).

The run checks itself in the same file: no tunnel above the ground outside its portals, no station above the street, no gradient over its limit, and no stretch under its minimum cover except 20.9 km near published platforms and portals. There remain 217 places where the gradient zig-zags by more than 1% in steps of 50 m, 68 of them with no platform, crossing, portal or junction nearby to explain it.

Who is on top

Where two lines cross, a 3D model has to say which passes over the other. The inventory in data/crossings.json lists 83 crossings, each with an expected order and a justification: a source for 27, an indirect proof such as a level plan for 22, and for 34 a rule. The rules are the ones of data/crossing-rules.json: a viaduct or a surface track goes over a tunnel, the L9/L10 goes under everything, high speed goes under the metro, FGC, Rodalies and the tram, and the newer tunnel goes under the older one. The script also looks for every other place where two tracks of different structures cross in plan, 556 in the current run, and orders them by the same rules (292 of them by construction alone).

The script then measures each crossing. Two boxes need 7.5 m between their rails: 1.5 m of floor under the upper one, 1 m of soil and 5 m from the lower rail to its roof. When an order or a gap is wrong, the coupled solve moves the line with less information, and a platform with a published depth stays within 2 m of it. Of the 83 inventory rows, 61 come out in order, 8 are on one level (Espanya’s L1 and FGC, as the project says, among them), 12 can’t be evaluated because a track doesn’t reach the crossing in the graph, and 2 are conflicts.

A few of the old interchanges show how thin the evidence is:

These heights then become the platform levels of each underground station in stations.json: 160 stations take them from rows of the research file, and 54 more, on tunnels without a row, from the solved profile.

How big a tunnel is

The shape of each tunnel comes from src/modules/railSections.ts. The bored tunnels have published sizes, and the code carries the source with them:

TunnelDiameterConfidence
L9/L10, one tube, stacked tracks11.96 mH, Generalitat TM-00509 (2008)
L9 to the airport, tracks side by side9.40 mH, same document
High speed, Sants–La Sagrera11.4 m outsideM, Ineco and Wikipedia
L8, Espanya–Gràcia10.23 mM, Trenscat; the city council gives 10.6 m

The 5.3 m between the two tracks of the L9 bore is a rule, from Trenscat’s description of the levels at Europa | Fira. Almost no box or vault has a published section. data/sections.json gives a source for the width of 10 stretches, copied to sectionSrc in network.json: the Gran Metro’s «Tipo TN» and «Tipo ZH» sections, 7.00 m of clear span for two tracks, the two Via Laietana tunnels of the L4, 4.80 m each, and the cover of the Aragó trench, 14.50 m of clear span. The last two give a width and no height. For the rest the sizes are defaults marked approx: a metro box is 5.0 × 5.2 m per track, and two tracks overlap into one box of about 9 × 5 m. Checked against the tallest vehicle of each system, the metro box had 0.40 m of headroom, and one line didn’t fit. The L1’s series 100 cars are 3.2 m wide and 4.31 m high, so its box was widened to 5.5 × 5.6 m.

Drawing depth so it reads

src/modules/networkSubsoil.ts sweeps each section along its profile into one mesh. A proof of concept had shown that from a kilometre away, 30 m of depth doesn’t register. So each tunnel gets a translucent curtain from its roof up to the ground, and depth can be scaled up to three times, measured from the fine terrain. From chunkOf():

const d = Math.max(0, g[k] - y[k]);
// Depth measured from the fine ground; the vertical scale deepens it. Above the ground (a portal's ramp) the rail stays.
railK[k] = y[k] <= g[k] ? g[k] - d * state.k : y[k];

The scale stretches the distance to the street, not the tunnels: a tube stays 11.96 m across, so crossings open up without the structures growing. When finer terrain tiles load, the stretches whose ground moved are measured again, as at the airports in laying an airport on real ground. The two Rodalies tunnels drawn this way are the ones behind why Rodalies can’t run more trains.

What the depths can’t tell you