Handling interchange stations in MetroFind
A worked example of keeping a physical station separate from its line-specific codes when searching, routing, and looking up train timings.
A journey through an interchange needs more information than two station names. In MetroFind, a route can reach Esplanade on one line and leave on another. The user sees one interchange, but the timing lookup still needs the code for the line used by each part of the journey.
This was part of the station-modeling work in April 2026. The fix involved carrying line information with a station instead of assuming that its primary code would work everywhere.
Follow one journey through the transfer
Take a route from Noapara through Esplanade to Sealdah. For the first segment, the lookup needs the origin and destination identifiers for the Blue line. For the next segment, it needs Esplanade’s Green-line identifier and Sealdah’s identifier on that line.
If the application carries Esplanade’s Blue-line code into the second lookup, the map can still look right while the timing request is wrong. That is a frustrating kind of bug because the visible route gives you little reason to question the request.
In the project’s seed data, Esplanade has line-specific codes such as KESP and KESP2. Keep those under the line they belong to:
1
2
3
4
5
6
7
const station = {
name: 'ESPLANADE',
codeByLine: {
1: 'KESP',
2: 'KESP2',
},
};
This is a reduced example of the representation, using the project’s identifiers. It is not a current service map.
The transfer joins the journey; each segment keeps its own line identifiers.
Resolve the code where you build the segment
A small helper makes the dependency obvious:
1
2
3
4
5
6
7
8
9
10
11
type StationCodes = {
name: string;
codeByLine: Record<number, string>;
};
function codeForLine(
station: StationCodes,
lineId: number,
): string | null {
return station.codeByLine[lineId] ?? null;
}
For the second segment in our example, codeForLine(station, 2) returns KESP2. An unknown line returns null. That gives the calling code a chance to show “timing unavailable” instead of silently trying the station’s primary code.
The real MetroFind helper also handles older station fields for compatibility. The important part is that its caller supplies the segment’s line. A helper cannot choose correctly if the caller has already thrown that information away.
Decide what a station ID means before grouping rows
There is another problem hidden in interchange data: two datasets may use IDs differently.
The checked-in sample contains 58 station rows but 55 station IDs. Esplanade, Kavi Subhash, and Noapara each appear twice under shared IDs. In that sample, grouping by ID lets the application combine the line records into one station for search.
Here is the simplified form of that operation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const grouped = new Map<number, {
id: number;
name: string;
codeByLine: Record<number, string>;
}>();
for (const row of rows) {
const station = grouped.get(row.id) ?? {
id: row.id,
name: row.name,
codeByLine: {},
};
station.codeByLine[row.lineId] = row.code;
grouped.set(row.id, station);
}
This code assumes that row.id identifies a physical station. If each line record has its own ID, it will keep the records separate.
That distinction matters in this project. Later seed data uses different IDs for same-name stations, whereas the sample fixture shares IDs at interchanges. The April client normalizer groups by ID; it does not reconcile those two conventions. MetroFind also has a separate name-and-line interchange resolver, which is why it is worth inspecting the whole route-building path rather than only the grouping function.
Before adapting this approach to another dataset, write down whether an ID means a place, a platform, or a station on a particular line. If you need all three concepts, give them separate fields. Merging every equal station name is tempting, but names can change or refer to different places. An explicit physical-station mapping is easier to review.
Test the transfer, not just the final path
A useful test should inspect the codes used by each segment. For our example, check that the first segment asks for the Blue-line version of Esplanade and the second asks for the Green-line version. A test that merely finds some path from Noapara to Sealdah can pass while those lookups are still wrong.
Also try a missing code. The route can remain visible while the affected timing is marked unavailable. That is more useful than hiding the whole journey, and safer than guessing an identifier.
The April implementation contains the full station builder, normalizer, and routing helpers. The sample station data makes the shared-ID assumption visible. Read them together; the normalizer’s behavior depends on the data it receives.
Project work: April 2026. Written in October 2026; revised November 2026.