Finding direct connections between stations

Hi, I’m making a network which models the london underground.
How could I use the API to find what stations/nodes are directly connected to each other? (I.e. you go on a train from station A directly to station B with no stops at any other stations)

Hi there! That’s a bit of a tricky one. I might suggest making a route sequence request for each of the lines you’re interested in. For example, for the District line, you can make a request to:

Then, the stopPointSequences and/or orderedLineRoutes properties will give you ordered sequences of stops for each route on that line.

You can obtain line IDs for the Tube lines from:

But for reference, they are:

  • bakerloo
  • central
  • circle
  • district
  • hammersmith-city
  • jubilee
  • metropolitan
  • northern
  • piccadilly
  • victoria
  • waterloo-city

Hi, thanks for responding. To be honest I don’t really have any knowledge on any of the stuff I’m doing I’m just kind of going with the flow since I’m just an a level student. Could you be a bit more in depth on what requesting that would do? I’m not catching on how this will help.

Perhaps I should ask what info does that request give me?

I kind of get it now I suppose, some info in that request will take me the sequence of the line so it’ll tell me the order at which the line will go so i can note down any direct connections

Would i be able to use this technique for finding the direct connections of every station on the underground? It seems like I would be able to.

Yes, you should receive a sequence of StopPoints (stations) for each route, which should tell you the direct connections of each Underground station.

That said, please be aware of some stations which share the same name but have different IDs. The ones I can think of are:

Also remember that at least two lines have unidirectional sections.

The Piccadilly Line has a Terminal 4 loop…


DLR Zone 1 trains don’t call at West India Quay outbound.

London Fields and Cambridge Heath normally don’t serve Chingford.


Watford Met is only served from Baker Street…

And Willesden Green appears in the above data sources for the Met but services only call there in one-every-10-years type emergences.


Here’s some sample code bits





1 Like

Your friend is Dijkstra’s … Dijkstra's algorithm - Wikipedia

How would Dijkstra’s help me when thats a shortest path finding algorithm?

That’s what it does! It can find both the shortest distance between two nodes OR the shortest distance to all nodes from a given point.

The main thing you need to decide is if you are going to use distance or time or simple “hops” as your “length” basis.

This is a JavaScript version we’re testing at the moment.

I see, I’m going to be using time for mine and I’m also going to use the A* Algorithm because i like it more.

If you like! I chose Dijkstra because it’s a Graph (in the maths sense) because the rail network is basically a Graph.

Yeah, to be honest the hardest part of this is creating the network lol. Atleast for me anyways but I’ve got it down now I know how to make all my edges now pretty much so all good. Thanks for your help guys.


How does one assign the “Weight” of the Edges - which is a critical factor for Djikstra’s algorithm. For example when you try to map a route from Morden (Northern line) to Warren Street (Northern), one would assume that going down a single line Northern would be the “shortest”, but consistently the route returned is Northern till Stockwell & then Victoria to Warren St - which indicates that the “distance” is a key factor (as much if not more than not changing lines)

1 Like

One could assume that but theres always different paths we can take on our network leading to different outcomes, therefore its not really a surprise that going just on one line is a bad idea. I think the more accurate weight we should use is the travel time between stations as its live updating whereas distance isn’t and doesn’t account for any delays or things like that. Sorry if I’ve completely missed ur point I’m just rambling on what I’m going to do personally.

No makes sense -

The point here is that the weights between the stations seems to be modelled on “time to travel” (rather than just distance)… The question would be if it would take longer to transit from one line to another in a station, would that be modelled in and if so how does it impact the weight of the vertex


There are two solutions to the Mornington Crescent issue. If you use geographic distance you can offset the true location of the station to make the Camden → Euston path via Mornington Crescent slightly longer. Another idea is to use the timetable to include the “dwell times” in the timetable.

The question of adding the transfer time (ie, the walking distance between platforms + half the service frequency) would give a good answer.

It depends on what you’re after as an answer: the fastest possible time OR the most cognitively simple route.

King’s Cross to Finsbury park has three routes on the tube map: one Thameslink stop, two on the Victoria Line and four on the Piccadilly.

As a passenger, of course, I know that there is same-level-interchange at Finsbury Park between the two tube lines.

1 Like

Infact I was going to ask this as a “feature request” - is there a way at every “interchange” holding some kind of weight/score for difficulty/ease of interchange between lines?

In case it’s of interest, here’s a blog post about a graph database we built called Pathfinder, which models not just stations but individual areas within stations and the time required to get between them. It gets especially complex when you consider timetables (a given edge might have a large weight if there is a long time until the next train departs).


@balac I had a Wikipedia Row about this once Template:Victoria Line RDT - Wikipedia has my Cross-planform-interchange map on but it was demoted due to being “too complicated for an encyclopaedia”