Inconsistent Naptan Ids


#1

I have been using the Journey Planner API for TFL. It works great for the most part but there is a discrepancy I have noticed in the api response.

In the response for the Journey Planner API request,

https://api.tfl.gov.uk//journey/journeyresults/51.51564%2C-0.1811/to/51.52557%2C-0.08807

I am looking for NaptanIds of departure points. These Ids are different for all stops as in, sometimes I get back an actual NaptanId like

“departurePoint”: {
"$type": “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “940GZZDLBNK”,
“platformName”: “”,
“icsCode”: “1000013”,
“commonName”: “Bank DLR Station”,
“placeType”: “StopPoint”,
“additionalProperties”: [],
“lat”: 51.51232119841,
“lon”: -0.08786127878
},

And sometimes I get back an Id that is different and does not correspond to the NaptanID of the station

“departurePoint”: {
"$type": “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “490G00133B”,
“platformName”: “”,
“icsCode”: “1000133”,
“commonName”: “Lancaster Gate Station”,
“placeType”: “StopPoint”,
“additionalProperties”: [],
“lat”: 51.51178015795,
“lon”: -0.17468494328
},

I have confirmed this by using the stop point API,

https://api.tfl.gov.uk/StopPoint/Search/Lancaster%20Gate?modes=tube

{ “$type”: “Tfl.Api.Presentation.Entities.SearchResponse, Tfl.Api.Presentation.Entities”, “query”: “Lancaster Gate”, “total”: 1, “matches”: [ { “$type”: “Tfl.Api.Presentation.Entities.MatchedStop, Tfl.Api.Presentation.Entities”, “icsId”: “1000133”, “topMostParentId”: “940GZZLULGT”, “modes”: [ “tube”, “bus” ], “id”: “940GZZLULGT”, “name”: “Lancaster Gate Underground Station”, “lat”: 51.511723, “lon”: -0.175494 } ] }

Could you please help me with this.


#2

Naptans can identify more than just the station (For example they can also identify individual entrances to a station.) This may be what’s happening here:

  • 940GZZLULGT seems to identify the station itself
  • 490G00133B seems to identify the bus stop cluster local to that station.

UK naptans and info can be found at https://data.gov.uk/dataset/naptan


#3

Hi Alistair,

Thanks a lot for your reply. Really appreciate it.

I am using these Naptan Ids to make further API calls to the Unified API and this causes issues because the response from the Journey API states this id to be a “tube station” but its actually not recognized as that.

Is there a way for me to get around this?


#4

the Journey API states this id to be a “tube station”

I think you’re reading too much into it. “commonName”: “Lancaster Gate Station”, “placeType”: “StopPoint”, only states that we’re at a place whose type is “StopPoint” and whose name happens to be “Lancaster Gate Station”.

but its actually not recognized as that.

Could you post up what request you’re making that gets this “not recognized” response?


#5

Hi Alistair,

I am trying to use these Ids to get arrival times for that stop using the API

So i plan a journey from point A to B, get the stop point ids and try to fetch arrival times for the stop points using API

https://api.tfl.gov.uk/StopPoint/940GZZLUASL/Arrivals

If the Naptan Id is not of the above format, it does not return arrivals to me.


#6

Any ideas what I can do?


#7

I’ve just written a longish post explaining NaptanIDs over here, in short to get a list of tube station StopPoints, query https://api.tfl.gov.uk/StopPoint/Mode/Tube and filter for StopPoints with a stopType of NaptanMetroStation.


#8

To answer the first part of your question, it will be because the journey leg is terminating at a station - our internal JourneyPlanner returns an ICS code for that Station which we attempt to translate into a Naptan. It looks like this is returning the id of the bus stop outside, rather than the top level station itself. I’ll create a ticket to investigate this. SVC-4436

You can work around this though - the GetById StopPoint API always returns you the whole NaPTAN hierarchy, from top to bottom. The intention is that if you have a platform NaPTAN ID or one from anywhere in that hierarchy, you will be returned enough information to work out what the Station is, and where the requested NaPTAN ID fits in that hierarchy.

So if you want to use the Arrivals API, you would then have the NaPTAN ID you need. Using your example of 490G00133B : https://api.tfl.gov.uk/StopPoint/490G00133B

{
  "$type": "Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities",
  "naptanId": "940GZZLULGT",
  "modes": [
    "bus",
    "tube"
  ],
  "icsCode": "1000133",
  "stopType": "NaptanMetroStation",
  "stationNaptan": "940GZZLULGT",
  "lines": [...],
  "children": [...]
  // etc.
}

You can see the root object in the response is the tube station, which is top of the heirarchy, with all of the other NaPTAN IDs collapsed into the children array (and their children, etc. down to the platform level). You can then use the NaPTAN ID of that top-most station to get Arrivals:

https://api.tfl.gov.uk/StopPoint/940GZZLULGT/Arrivals

[
  {
    "id": "-1709983665",
    "operationType": 1,
    "vehicleId": "014",
    "naptanId": "940GZZLULGT",
    "stationName": "Lancaster Gate Underground Station",
    "lineId": "central",
    "lineName": "Central",
    "platformName": "Eastbound - Platform 2",
    "direction": "outbound",
    "bearing": "",
    "destinationNaptanId": "940GZZLUEPG",
    "destinationName": "Epping Underground Station",
    "timestamp": "2017-09-15T11:44:17Z",
    "timeToStation": 355,
    "currentLocation": "At Shepherd's Bush",

Hope that helps!


#9

Hi somedeveloper, this issue has been fixed.