01 One network for metro and tram
In Lyon, the tram doesn't run on the outskirts: it crosses the city and meets the metro at every major hub. So I put lines A to D and T1 to T7 in a single network, played in the same grid. The Fourvière and Saint-Just funiculars are not lines of the game.
As for the other cities, everything is produced by a Django command, import_tcl, which I can rerun: it reads seven downloaded files, queries Wikipedia, checks the result and writes lyon/stations.json, which the game loads into the database on each deployment.
make import-lyon # downloads the layers, then: manage.py import_tcl <stops> <metro traces> <tram traces> <exits> <stations> <rivers> <water bodies>
make load-stations
02 The sources
| Source | Publisher | License | What I take from it |
|---|---|---|---|
| Stops, metro and tram lines, entrances and exits (data.grandlyon.com, WFS) | SYTRAL Mobilités | Licence ouverte 2.0 (Open License 2.0) | Platforms, lines served, commune, route and color of each line, exits |
| Rivers and water bodies (data.grandlyon.com, WFS) | Métropole de Lyon | Licence ouverte 2.0 | The axes and the banks of the Rhône and the Saône |
| French Wikipedia (MediaWiki API) | Wikimedia | CC BY-SA 4.0 | Full names, opening year, level, tram terminuses, ridership |
| Passenger stations (Gares de voyageurs) | SNCF | ODbL | Connections with the train |
| Administrative divisions API (Découpage administratif) | Etalab | Licence ouverte | The 58 communes of the Métropole |
The TCL network also publishes a GTFS, the usual format for transit timetables, but downloading it requires an account. I preferred SYTRAL's public map layers, served over WFS: a standard protocol that returns the objects of a map as GeoJSON, with no authentication. What anyone can download, anyone can check.
03 The WFS format
A WFS request is a simple URL: the name of the layer, the output format and the coordinate system you want.
GET https://data.grandlyon.com/geoserver/sytral/ows?SERVICE=WFS&VERSION=2.0.0&request=GetFeature
&typename=sytral:tcl_sytral.tclarret&outputFormat=application/json&SRSNAME=EPSG:4326
EPSG:4326 asks for longitudes and latitudes in degrees, like a GPS. The response is a collection of GeoJSON objects, one per platform. Here is one of the four at Bellecour, stripped of a few fields:
{
"type": "Feature",
"id": "tcl_sytral.tclarret.30103",
"geometry": {"type": "Point", "coordinates": [4.8330193, 45.75762738]},
"properties": {
"id": 30103,
"nom": "Bellecour",
"desserte": "A:A",
"pmr": true,
"commune": "Lyon 2e Arrondissement",
"insee": "69382"
}
}
Mind the order: GeoJSON writes longitude before latitude. The desserte field lists the lines that stop at this platform, each followed by its direction: A:A is line A in the outbound direction (aller), A:R in the return direction (retour). A neighboring bus stop carries BRMD:R,BRMD:A,C12:A,PL2:R.
04 Ordering the stations along a route
I read the stops layer and keep the metro and tram platforms. The splitting of desserte compares each line as a whole: searching for the letter "A" in the text would also find the bus lines BRMA or PL2:A.
def served_lines(desserte: str | None) -> list[str]:
"""The lines of a `desserte` ("BRMB:R,C12:A" -> ["BRMB", "C12"]), each token compared whole."""
return [token.partition(":")[0] for token in (desserte or "").split(",") if token]
for feature in read_features(path):
properties = feature["properties"]
served = served_lines(properties["desserte"])
lon, lat = feature["geometry"]["coordinates"]
metro = tuple(line for line in METRO_LINES if line in served)
tram = tuple(line for line in TRAM_CODES if line in served)
if not metro and not tram:
continue
...
(platforms if metro else tram_platforms)[properties["nom"]].append(point)
The platforms are then grouped by name to form the stations: 42 for the metro, with Charpennes, Hôtel de Ville, Bellecour and Saxe - Gambetta each counted only once.
Without a GTFS, there is no ordered list of stops. I rebuilt it from geometry. Each platform is projected onto the "outbound" route of its line: for each segment of the route, I compute the point closest to the platform, and I keep the best one, along with the distance traveled since the start of the route.
def project(trace: Sequence[tuple[float, float]], lat: float, lon: float) -> tuple[float, float]:
px, py = _plane(lat, lon)
best = (float("inf"), 0.0)
travelled = 0.0
for (lon1, lat1), (lon2, lat2) in pairwise(trace):
x1, y1 = _plane(lat1, lon1)
x2, y2 = _plane(lat2, lon2)
dx, dy = x2 - x1, y2 - y1
length = (dx * dx + dy * dy) ** 0.5
t = (
0.0
if length == 0
else max(0.0, min(1.0, ((px - x1) * dx + (py - y1) * dy) / length**2))
)
distance = ((px - (x1 + t * dx)) ** 2 + (py - (y1 + t * dy)) ** 2) ** 0.5
if distance < best[0]:
best = (distance, travelled + t * length)
travelled += length
return best[1], best[0]
_plane converts latitude and longitude into meters on a plane: at the scale of a city, the Earth is flat enough for that, as long as you multiply the longitudes by the cosine of Lyon's latitude. t is the position of the foot of the perpendicular on the segment, clamped between 0 and 1 to stay on it.
The stations are then sorted by distance traveled. And everything is checked:
if (far := max(distance for _, distance in found)) > TRACE_RADIUS:
raise CommandError(f"Line {line}: {name} is {far:.0f} m from its trace.")
...
if len(ordered) != LINE_SIZES[line]:
raise CommandError(f"Line {line}: {len(ordered)} stations, {LINE_SIZES[line]} known.")
A platform more than 150 m from the route, two stations in the same place, or a line that doesn't have the expected number of stations (14 for A, 12 for B, 5 for C, 15 for D) makes the import fail. A change to the network, like the two stations added to line B in 2023, has to be made on purpose.
05 Merging metro and tram
A metro station and a tram stop that share the same name, less than 200 m apart, are just one station. I needed an explicit rule: SYTRAL's stations layer groups the metro platforms, but never with the tram ones.
groups: dict[str, Group] = {}
for name, points in network.platforms.items():
key = normalize(name)
if key in groups:
raise CommandError(f"Two metro stations named {name}.")
groups[key] = Group(key, list(points), [])
for name, points in network.tram_platforms.items():
key = normalize(name)
group = groups.setdefault(key, Group(key, [], []))
if group.metro and not any(
haversine(m.lat, m.lon, t.lat, t.lon) <= MERGE_RADIUS for m in group.metro for t in points
):
raise CommandError(f"{name}: a tram stop and a metro station far apart.")
group.tram += points
normalize ignores accents, case and hyphens. Eleven stations are shared this way, from Charpennes to Vaulx-en-Velin - La Soie, and they are the ones that answer the metro-tram connection criterion. The rule has its deliberate limits: Gare Part-Dieu - Villette, on the other side of the station, remains a separate station from Gare Part-Dieu - Vivier Merle.
In total: 42 metro stations, plus 113 tram stops, minus 11 in common, which makes 144 stations.
06 From abbreviated names to full names
For the metro, the displayed name is the title of the station's Wikipedia article, matched to the platform through the coordinates in its infobox, with the same code as for Lille. Perrache is an exception: its article describes the whole interchange hub, so I simply keep "Perrache".
For the tram, it's trickier: platform names are abbreviated to fit on a sign, like "Boutasse - C. Rousset" or "Hôp. Feyzin Vénissieux". The full names come from Wikipedia's navigation templates, one per tram line. To match them, each pair gets a score: the number of words of the abbreviated name that start a distinct word of the full name, in any order.
def name_score(tcl: str, full: str) -> int:
free = _tokens(full)
score = 0
for token in _tokens(tcl):
for word in free:
if word.startswith(token):
free.remove(word)
score += 1
break
return score
"C." starts "Camille", "Hôp." starts "Hôpital", "Bron Hôtel de Ville" finds "Hôtel de Ville - Bron". Removing each used word from free keeps the same word of the full name from counting twice. Ordinals are reduced to their number ("8ème" and "8e" become 8). Pairs are taken from best to worst, line by line, and a stop shared by several lines must get the same name everywhere. If a stop is left without a name, the import stops.
07 Commune, arrondissement and rivers
Each SYTRAL platform carries its commune and its INSEE code. Lyon's arrondissements have their own codes, from 69381 for the 1st to 69389 for the 9th. I read the number in the name ("Lyon 2e Arrondissement") and I check that it matches the code, two fields that must say the same thing:
for point in points:
found = ARRONDISSEMENT.match(point.commune)
if found is None:
found_in[point.commune].append(point)
continue
number = int(found.group(1))
if point.insee != f"693{80 + number}":
raise CommandError(f"{point.name}: {point.commune} has the INSEE code {point.insee}.")
found_in[LYON].append(point)
arrondissements[LYON].add(number)
A station whose platforms are in two arrondissements counts for both: Garibaldi, Saxe - Gambetta or Grange-Blanche, for example. Desgenettes is the only one that straddles two communes, Lyon and Bron; it takes the one with the most platforms, Bron.
For the rivers, I start from the outlines of the Métropole's water bodies. Each bank segment within 1.5 km of a station is assigned to the Rhône or the Saône depending on the nearest of four axes: the Rhône, the Vieux Rhône, the Miribel canal and the Saône. Then, for each station, I measure the distance from its nearest platform to the bank, not to the middle of the river. The criterion "within 500 m of the Rhône" thus counts 20 stations; Musée des Confluences is the closest, at 30 m.
The criterion "west of the Rhône" is read from the arrondissement and the commune. But the import checks it against the geometry: a ray cast east from each station must cross the river, or not, as expected.
for group in groups:
station = stations[names[group.key]]
if east_of_rhone(group, banks) != on_rhone_left_bank(station.commune, station.arrondissements):
raise CommandError(f"{station.name}: the Rhône and its commune disagree on its bank.")
Two independent sources, the administrative one and the geographic one, must say the same thing.
08 Years, levels and exits
The metro's opening year comes from Wikipedia's infoboxes. Vieux Lyon required special care: its infobox mixes the metro (1991) and the funiculars (1878 and 1900), which I remove. For the tram, the years come from the articles of each line, split into sections; the import checks that the sections cover the whole line, with no gap or overlap. A station with several lines takes the oldest year.
The thresholds of the opening criteria are placed just after two years with no opening at all: if a source is off by a year on a tram stop, the answer doesn't change.
The level also comes from the infoboxes: 40 underground stations, Croix-Paquet included, in an open cut. Tram stops are at ground level, except the one at Perrache, under the interchange center.
The number of exits counts the distinct entrances in the layer of metro stations that serve the station's platforms: Bellecour has 9, the record.
09 Ridership, a special case
No open source gives the ridership of Lyon's stations: the network doesn't publish it. The only one I found is a table in the article "Liste des stations du métro de Lyon" (list of Lyon metro stations), with no source, which mixes figures from 2017 and 2024, in passengers per day. I read it cell by cell in the wikitext, and the format is strict:
number = re.fullmatch(r"(\d[\d\s \xa0]*) \((2017|2024)\)", value)
if number is None:
raise CommandError(f"{title}: a ridership of {value!r}.")
figures[title] = int(re.sub(r"\D", "", number.group(1)))
"6 379 (2017)" gives 6379, whatever the space between the thousands (normal, thin or non-breaking). Another year, another format, and the import stops: if the article changes, I want to know. The ID of the revision read is displayed on each import.
Rather than mixing these figures with Paris's annual figures, I keep them in a separate field, and I only draw one criterion from them: more than 20,000 passengers per day. The threshold falls in a big gap: ten stations exceed it, from Bellecour (almost 120,000) to Part-Dieu, and the next one, Guillotière, is at 18,000. Whether a given figure dates from 2017 or from 2024 doesn't push any station to the other side.
The opposite criterion, fewer than a given number of passengers, is not offered: most tram stops have no figure, and would be wrongly rejected.
10 The only hand-written list
There is no open data saying whether a station's name honors a person: Wikidata knows it (property P138, "named after") for only 7 stations. So I wrote a list, by reading the articles of the stations and of the streets they are named after: 78 stations, saints included, with the origin of each noted as a comment in the code. Guichard for Claudius Guichard, Villon for the painter Eugène Villon, Grandclément for the mayor Jules Grandclément.
When the origin isn't sourced (Debourg, Bachut, Gerland…), the station is not in the list. A name that isn't a person, like Croix-Luizet or Vinatier, isn't either. And the import fails if the list mentions a station that doesn't exist.
11 The criteria that come out
A criterion is only playable if it has at least 2 stations and at most 70% of the network. About a hundred criteria pass this filter:
| Family | Examples | Source |
|---|---|---|
| Network | Lines A to D and T1 to T7, terminus, metro-tram and train connections, automatic metro (B and D), at least 5 exits | SYTRAL, SNCF, Wikipedia |
| Place | Arrondissement, commune, outside Lyon, Presqu'île, west of the Rhône, near the Rhône or the Saône, underground | SYTRAL, Métropole de Lyon, Wikipedia |
| History | Opened before or since a given year, more than 20,000 passengers per day | Wikipedia |
| Trivia | Named after a personality | Hand-written list |
| Name | Letters, length, number of words, name of a commune of the Métropole, starts with "Gare" | The name itself |
Lyon's lines have prefixed values in the database (lyon-A, lyon-T1): without that, line A of the Lyon metro and RER A in Paris would share the same criterion. Some criteria will never come out: the 5th arrondissement has only one station, Vieux Lyon, and "east of the Rhône" counts 124 out of 144.
12 What's missing
The Paris criteria that rely on station-by-station lists (nearby places, women, writers, battles, ghost stations…) don't exist in Lyon: those lists remain to be written. If you have a source, the criteria ideas page is there for that.