01 Metro and tram in the same grid

Toulouse has two automatic metro lines, A and B, and one tram line, T1, which runs from the Palais de Justice toward Blagnac. As in Lyon, I put them in a single network: 37 metro stations, 25 tram stops, two of them shared, which makes 60 stations.

The T2 branch to the airport closed in 2023 and no longer appears in Tisséo's data: it is not in the game. The Téléo cable car (route_type 6 in the GTFS) and the buses aren't either.

As for every city, a Django command, import_tisseo, reads the downloaded files, queries Wikipedia and the communes API, checks the result and writes toulouse/stations.json.

BASH
make import-toulouse  # downloads, then: manage.py import_tisseo tisseo-gtfs.zip gares-de-voyageurs.csv bdtopo-garonne.json
make load-stations

02 The sources

Source Publisher License What I take from it
GTFS of the Tisséo network Tisséo Collectivités, via data.gouv.fr ODbL Lines, colors, station order, positions
French Wikipedia (MediaWiki API) Wikimedia CC BY-SA 4.0 Names, opening year, metro level; list of tram stops
Administrative divisions API (Découpage administratif) Etalab Licence ouverte (Open License) The commune of each station
Passenger stations (Gares de voyageurs) SNCF ODbL Connections with the train
BD TOPO (topographic database), watercourses layer (Géoplateforme, WFS) IGN Licence ouverte 2.0 The course of the Garonne

Tisséo's GTFS is published on the Toulouse Métropole portal, but its address changes with each update. I download it through data.gouv.fr, which gives a stable address to the latest version. The course of the Garonne is requested from IGN's WFS service with a filter on its name (toponyme='la Garonne'): 340 KB instead of the whole BD TOPO.

03 From the GTFS to the stations

The GTFS is an archive of CSV files. In routes.txt, the lines are those of type 1 (metro) named A and B, and the one of type 0 (tram) named T1:

TEXT
route_id,agency_id,route_short_name,route_long_name,route_color,route_text_color,route_type
line:61,network:1,A,Basso Cambo / Balma - Gramont,db001b,ffffff,1
line:69,network:1,B,Borderouge / Ramonville,ffdd00,000000,1
line:68,network:1,T1,Palais de Justice / MEETT,004687,ffffff,0

The columns are not in the same order as in Lille's GTFS, and the colors are in lowercase: the format fixes the column names, not their position. So I read each row as a dictionary, by column name (csv.DictReader), and I normalize the colors to #DB001B.

To order the stations, I reuse the function written for Lille: I read stop_times.txt just once, as a stream, and the longest sequence of stops in direction 0 gives the line. All the other trips must be pieces of it: those are the trains that turn around before the terminus, at Odyssud-Ritouret or Aéroconstellation. A trip that left the path makes the import fail.

Tisséo groups its platforms into stop areas: in stops.txt, a row with location_type 1 is an area, and each platform (location_type 0) points to it through parent_station. Grouping by name, as in Lille, wouldn't work here:

TEXT
stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,platform_code,wheelchair_boarding
stop_area:SA_1707,,Jean Jaurès,43.60592336728775,1.4490828635802229,1,,,1
stop_area:SA_2224,,Jean Jaurès,43.52396069993558,1.3989850860737574,1,,,1
stop_area:SA_26,,Jean Jaurès,43.50626962210932,1.3234464724227242,1,,,1
stop_point:SP_1072,12970,Jean Jaurès,43.50600686012319,1.3230782121418438,0,stop_area:SA_26,,1

Three areas are called Jean Jaurès: the metro station, in the center, and two bus stops about ten kilometers to the southwest. So I only keep the areas of the platforms served by the trips of A, B and T1, and I identify them by their stop_id, not by their name.

Both directions, and the lines of a same station, are gathered in the same area: Arènes (A and T1) and Palais de Justice (B and T1) are thus single stations. I add a safety rule: two areas with the same name less than 200 m apart are just one station, and two areas with the same name far apart are an error.

Finally, the import counts the stations:

PYTHON
LINE_SIZES = {"A": 18, "B": 20, "T1": 25}

One station more or fewer on a line, and it stops: a change to the network has to be made on purpose.

04 Wikipedia, stitched together by geography

For the metro, I read the articles of the categories "Station de la ligne A du métro de Toulouse" and "… ligne B", and their infobox: name, opening year, position (underground or elevated), coordinates.

Each article is attached to the station closest to its coordinates, within 300 m, each article only once. Three articles have no coordinates (Mirail - Université, La Vache, Faculté de Pharmacie): those are attached by name. The articles of stations not yet open, like Parc du Canal or Labège Madron, are discarded: "planned for 2027" is not an opening year. The nom field can also contain a wikitext pictogram ([[Image:…]]), which I remove.

Wikipedia and Tisséo don't spell everything quite the same way: Jean-Jaurès, Canal-du-Midi or Université-Paul-Sabatier take hyphens in the encyclopedia, not on the platforms. I keep Tisséo's spelling, the one you read in the station, with a small table of corrections in the code.

For the tram, I read the article "Liste des stations du tramway de Toulouse" (list of Toulouse tram stops): the "Stations en service" (stations in service) table gives the name, the year and the coordinates of each stop, also attached to its area by distance, within 150 m. The rows of the former airport branch are ignored, and the import fails if a T1 stop is missing on one side or the other.

Years What opens
1993 Line A, from Basso Cambo to Jolimont
2003 The extension of A to Balma - Gramont
2007 Line B
2010 – 2013 Tram T1, as far as Palais de Justice
2020 MEETT, the exhibition center

The thresholds of the opening criteria (before 2005 or 2009, since 2009 or 2012) fall in the middle of two years with no opening: a one-year error in a source changes no answer.

05 The bank of the Garonne

This is Toulouse's own criterion: is the station on the left bank, west of the river, or on the right bank, to the east?

The course is requested from IGN's WFS service, filtered on the name of the watercourse with a CQL condition:

TEXT
GET https://data.geopf.fr/wfs/ows?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature
    &TYPENAMES=BDTOPO_V3:cours_d_eau&outputFormat=application/json&SRSNAME=CRS:84
    &CQL_FILTER=toponyme='la Garonne'

CRS:84 gives longitudes and latitudes in degrees, longitude first. The response is GeoJSON: each object is a MultiLineString, a list of broken lines, each one a list of points.

JSON
{
  "type": "Feature",
  "id": "cours_d_eau.4918",
  "geometry": {
    "type": "MultiLineString",
    "coordinates": [[[-0.52833636, 44.80873637], [-0.52937157, 44.81052389], [-0.52965182, 44.81115573], ...], ...]
  },
  "properties": {
    "code_hydrographique": "05C0000002000894629",
    "toponyme": "la Garonne",
    "statut_du_toponyme": "Validé",
    ...
  }
}

The filter returns seven objects named "la Garonne". The river itself, in 126 pieces and 11,450 points, from the Pyrenees to Bordeaux. A secondary arm, which goes around islands and heads off in every direction. And five homonymous streams, in the Var and the Gard, more than 200 km away. I only keep the biggest object, the one with the most points, and I cut it into segments, projected onto a plane in meters:

PYTHON
features = [f for f in read_features(path) if f["properties"]["toponyme"] == GARONNE]
if not features:
    raise CommandError(f"No axis for {GARONNE}.")
main = max(features, key=lambda f: sum(len(part) for part in f["geometry"]["coordinates"]))
segments: list[Segment] = []
for part in main["geometry"]["coordinates"]:
    plane = [_plane(lat, lon) for lon, lat in part]
    segments += list(pairwise(plane))

IGN draws its watercourses in the direction of the current: each segment goes downstream. To know on which side of a segment a station falls, all you need is the sign of a cross product between the segment and the vector going from its start to the station: positive on the left, negative on the right.

PYTHON
def side_of(point: tuple[float, float], segment: Segment) -> tuple[float, float]:
    (x1, y1), (x2, y2) = segment
    dx, dy = x2 - x1, y2 - y1
    length = dx * dx + dy * dy
    t = max(0.0, min(1.0, ((point[0] - x1) * dx + (point[1] - y1) * dy) / length))
    nearest = (x1 + t * dx, y1 + t * dy)
    distance = ((point[0] - nearest[0]) ** 2 + (point[1] - nearest[1]) ** 2) ** 0.5
    return distance, dx * (point[1] - y1) - dy * (point[0] - x1)


def bank_of(group: Group, axis: Sequence[Segment]) -> Bank:
    point = _plane(*group.centre)
    _, side = min((side_of(point, segment) for segment in axis), key=lambda found: found[0])
    return LEFT_BANK if side > 0 else RIGHT_BANK

Only the nearest segment matters: far from the river, a meander can pass on the other side of a station, and a distant segment would give the wrong answer. The left bank, looking downstream, is to the west in Toulouse.

The Île du Ramier, between two arms, is to the left of the main channel: it counts as left bank. Result: 33 stations on the left bank, from Saint-Cyprien to Blagnac, and 27 on the right bank, from Capitole to Borderouge.

06 Commune, tram and train

The commune comes from the Découpage administratif API, queried with the position of each station, and the département must be Haute-Garonne (31), otherwise the import stops. Toulouse has 46 stations out of 60: too many for a criterion, which wouldn't separate anything. So I offer "outside Toulouse" (14 stations) and Blagnac (10, all on the tram).

A station has a train connection if one of its platforms is within 250 m of an SNCF station: Arènes, Marengo - SNCF for Matabiau, and Saint-Agne - SNCF.

The whole Toulouse metro is a driverless VAL: the automatic metro criterion counts the 37 metro stations, and leaves the tram aside.

07 The only hand-written list

No open data says whether a station's name honors a person. So I wrote a list of 13 stations, each one checked in its Wikipedia article, with the justification as a comment above the list: Jean Jaurès, Saint-Cyprien, or La Vache, from the nickname of Jehan Calmet. Names that aren't people (Capitole, Carmes, Arènes) are not in it, nor are those whose origin no source gives, like Compans-Caffarelli, Purpan or Empalot. The import checks that every name in the list is really a station.

08 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 sixty pass this filter:

Family Examples Source
Network Lines A, B and T1, terminus, two lines or more, metro-tram and train connections, automatic metro GTFS, SNCF
Place Outside Toulouse, Blagnac, bank of the Garonne, underground, at ground level Administrative divisions API, IGN, Wikipedia
History Opened before or since a given year Wikipedia
Trivia Named after a personality Hand-written list
Name Letters, length, number of words, "Saint", "de", "du" The name itself

As in Lyon, lines have prefixed values in the database (toulouse-A, toulouse-B), so as not to be confused with RER A and B in Paris.

09 What I didn't use

  • Ridership. The list of tram stops gives one figure per stop, but from 2016, repeated identically for Hippodrome and Arènes, and the metro infoboxes mix 2016 and 2018. Figures that can't be compared with each other don't make a criterion.
  • Exits. Tisséo's GTFS doesn't describe the station entrances.
  • Nearby places and trivia: in Paris, they come from lists written station by station, which don't exist yet for Toulouse.

If you know a source for any of these, the criteria ideas page is waiting for you.