Station Locations

Hi everyone,

I’m looking for a list of station lat/longs. There seems to be a reference to this on TfL’s list of available APIs under ‘station locations’ but I cannot seem to find this data within the API portal itself. I’m just looking for the station name and a singular lat/long for that station, and if anyone could point me in the direction of where I’d be able to obtain this I’d be very grateful.

Hi, which modes of transport do you want the station locations of?

For example, if you are only interested in Tube stations, you can get the data from:
https://api.tfl.gov.uk/StopPoint/Mode/tube

If, instead, you want Elizabeth line stations and London Overground stations, you can find them at:
https://api.tfl.gov.uk/StopPoint/Mode/elizabeth-line,overground

Just provide a comma-separated list of mode IDs in the URL.

You can find out what modes we support (and their IDs) from:
https://api.tfl.gov.uk/Line/Meta/Modes

The StopPoint objects contain lat and lon properties for the latitude and longitude, respectively.

1 Like

@LeonByford
It would be useful to use that method to get all bus stop locations with lat/lon so I tried https://api.tfl.gov.uk/StopPoint/Mode/bus. That gives the error: “Bus mode must be paginated as data set is too large.”
Can the entire set be downloaded directly (without using a browser) or is pagination an essential API option for that as well? If so how to implement it?

Hi, pagination is essential to retrieve the bus stops.

This can be done by making requests such as:
https://api.tfl.gov.uk/StopPoint/Mode/bus?page=1
https://api.tfl.gov.uk/StopPoint/Mode/bus?page=2

https://api.tfl.gov.uk/StopPoint/Mode/bus?page=37

The response object includes pageSize, total and page properties to assist with this.

To work out the total number of pages, use the formula ceil(total/pageSize). For example: ceil(36052/1000) = ceil(36.052) = 37

I think last time I tried to do this, it took about two minutes to download all 37 pages sequentially.

Thanks for the prompt advice. I will probably write a simple script to do it for me.

If it’s just for a one-off, you can probably run a curl command like:

curl "https://api.tfl.gov.uk/StopPoint/Mode/bus?page=[1-37]" -o "bus_stops_#1.json"

Thanks for your response! However, I can see the lat/longs for Overground, Elizabeth etc on their respective objects but not on the Tube data?

The lat/lons are in there, but please note that the StopPoint data is a hierarchy rather than a flat array. You may need to use the children property of a StopPoint to work your way down to a StopPoint that does contain lat/lons.

1 Like

Brilliant!
It took a bit longer than two minutes but worked perfectly. Thanks again for your help.

1 Like

Ah I see them now. Thanks for your help, it’s greatly appreciated.

1 Like

@LeonByford (or anyone)
Following your recent suggestion I have been investigating the set of bus StopPoint JSONs returned by the API. There is one really useful field (not in the NaPTAN downloads) that I would like to add to my existing database - the locations shown on each bus stop to indicate the direction of travel.

If there is an API call to return just that field plus the corresponding NaPTAN ATCO for each relevant bus stop it would be vastly preferable to attempting to extract it from 37 large JSON files. The JSON data location is:
category, key, sourceSystemKey, value
Direction, Towards, CountDown, [eg Hinchley Wood]

Thanks.

@misar

I think what you want forms column 17 (“Bearing”) of

https://beta-naptan.dft.gov.uk/Download/National/csv

(from memory bus stops are “StopType”=‘BCT’)

@briantist
I already have those (the compass points or bearings).

In the TfL JSONs they are the values for:
“category”: “Direction”,
“key”: “CompassPoint”,
“sourceSystemKey”: “Naptan490”,
“value”: “W”

Whereas I want:
“category”: “Direction”,
“key”: “Towards”,
“sourceSystemKey”: “CountDown”,
“value”: “Balham Or Clapham Junction”

I would still be interested to hear whether the API call I requested exists but it was easier than I thought to extract fields from the set of 37 .json pages. “Towards” and “lines” (bus routes served) are really useful StopPoint data but I have not found them in any publicly available .csv/.xlsx downloads.

@misar I think - think - what you want might be in the https://tfl.gov.uk/tfl/syndication/feeds/journey-planner-timetables.zip file. It’s XML TransXChange format.

@briantist I have been using those zips for several months, primarily to maintain an up-to-date database of route sequences. A list of routes calling at each stop could be extracted with some code but if the “Towards” data is there it has eluded me. The values are the localities displayed as directional guidance at bus stops, not necessarily the bus destinations. For example, in post #10 I mentioned Hinchley Wood which is not a destination of the bus (K3) serving the stops with that value.

@misar

Just looking at my code that decodes those files, I seeing the code look for “DynamicDestinationDisplay” which only appears in the TfL data (not the UK-wide data).

$arrDynamicDestinationDisplays[$JourneyPatternSectionID] = SearchDOMDocument::searchByArray($JourneyPatternTimingLink, ['DynamicDestinationDisplay']);

Does this list what your are after?

@briantist No.
TransXChange_common.xsd reveals this:

		<xsd:element name="DynamicDestinationDisplay" type="NaturalLanguageStringStructure" minOccurs="0">
				<xsd:annotation>
					<xsd:documentation>**Journey destination** applicable to vehicle at referenced Stop. @lang.</xsd:documentation>
				</xsd:annotation>
			</xsd:element>

The “towards” values are mostly not the journey destinations. They are not dynamic and are printed at bus stops.

'490015700C British Library Stop C C 51.529025 -0.1266 Angel Islington; Tufnell Park Or Holloway n91;n205;390;n73;91;30;205;73


(flickr Creative Commons Licence)

Perhaps you could compile the list of things in the “toward” list from the destinations of the routes serving the stop?

towards “most frequent destination”, “second-frequent destination” or “other destination”

Similar issue with this group of stops near St Pancras (as an example).

Order by frequency and then combine names would give stop A:

  • Oxford Circus
  • Trafalgar Square
  • Victoria
  • Marble Arch
  • Paddington

A would be therefore be…

“towards Oxford Circus, Trafalgar Square or Victoria”

@briantist "Oxford Circus, Trafalgar Square or Victoria” is factually correct in that there are buses from Stop A heading towards those destinations but apparently it is not what is printed on the stop:

72626 490004722A St Pancras International Stop A 235 W 29-31 Euston Road St Pancras London London WC1H 8NP Tottenham Court Road; Russell Square Or Baker St n73;n91;n205;390;73;91;205;30

If anyone reading this thread happens by St Pancras International in the next few days perhaps they could take a photo of Stop A for us. :smiley:

Edit: Google did it already!