I am looking for an API, that can provide detailed information on bus stops, train stations, underground stations/stops, overground stations/stops, and other public transportation stops and stations based on specified latitude and longitude coordinates.
To illustrate, in the accompanying Google Maps image focused on Elephant & Castle in London, I’ve highlighted various public transportation stops and stations, including bus stops, the Elephant & Castle Underground station, and the Elephant & Castle Rail station.
My goal is to access similar data on a national scale for all public transportation.
While I’ve been advised to use the NaPTAN API for this purpose, I find myself lacking the knowledge on how to navigate it. I’m uncertain about where to initiate the process and lack any guidance on utilizing the NaPTAN API effectively.
As far as I know, there is no API that will directly do what you want. The Tfl API has such an interface, but for London only.
I suggest that you have a look at the documentation first, particularly the examples in section 9, which show the sort of hierarchy between StopAreas and StopPoints, and also the description of StopPoint types and their geolocations in section 3.5.11
You would then need to download and process the NaPTAN dataset periodically, say weekly, and then use that data as the source, typically extracting all StopPoints of the types you want whose spatial co-ordinates are within a particular distance from the central point you are displaying.
You might well find that you want a database for the first part, with a small API for the second part, which your iOS app can invoke.
Also bear in mind that, supposing you then wanted to display route, timetable or arrival data at these stops, you need to look at the TNDS, BODS and Network Rail APIs for this data - a whole further set of complex data…
Can someone guide me through the process of using the NaPTAN API? Alternatively, has anyone utilized this API before, or are there other APIs available for obtaining comprehensive information about bus stops, train stations, underground and overground stations, as well as other public transportation stops and stations on a national or global scale, with specified latitude and longitude coordinates?
For those with expertise, I primarily have a background in iOS mobile development. If feasible, could you provide me with a detailed, step-by-step guide on how to get started with the NaPTAN API? The API documentation can be found here.
The page you linked says it all. The API is just a way to download the NaPTAN datasets and the working examples are all there is. As it says on that page:
Want something more simple?
You can download the NaPTAN & NPTG datasets in CSV and XML format from the new NaPTAN website.
Hi there! To help keep the forum organised, I have merged your two related threads. Also, please note that the NaPTAN dataset is not a TfL service and therefore TfL cannot provide formal support for it.
As has been mentioned, NaPTAN requires a certain amount of technical, domain and even some mathematical knowledge to use. Other APIs and datasets may be easier to use.
You might also like to see if there is a library you can use. There seems to be a couple available for Python, for instance, and at least one for R.
If you do need to use the raw NaPTAN dataset, then this is available in a CSV version or an XML version. The CSV version is easier to use, but the XML version is more comprehensive. Either way, you will probably want to read in the file and use either a CSV parser or an XML parser as appropriate to help you process the data.
@LeonByford@nickp@misar@Poggs I appreciate your prompt responses – thank you. I’m currently facing a challenge when it comes to extracting the necessary data from the CSV file I’ve downloaded. It’s quite confusing for me, and I’m reaching out for assistance. I suffer from dyslexia and it adds an extra layer of difficulty, and the complexity of the documentation gives me a headache.
I want to express my deepest gratitude and appreciation. It would mean a lot to me if someone could generously help me by providing detailed, step-by-step instructions on how to obtain the specific data I’m looking for. Not only will this be so valuable to me but also make a significant difference in my learning. Thank you so much. Thanks
Also, could you recommend any libraries that might simplify the process of obtaining the data I need? Your guidance would be immensely valuable in helping me navigate through this.
Provide immininent arrival times for every route/service at each location
Have a planner for every possible journey using any chosen mode(s) of transport.
You said in your first post that “My goal is to access similar data [to Google Maps] on a national scale for all public transportation.” I don’t want to be discouraging but if you meant that literally it is an almost impossible task for even an experienced programmer. Google makes it seem trivial but that is only possible by applying vast resources.
The NaPTAN CSV you downloaded is one small part, allowing just searches for stops by various terms and plotting them. Even that is incomplete. For example, to search by postcode I needed to add the data from another source. Likewise you mentioned using latitude/longitude. For reasons which escape me NaPTAN only provides grid coordinates for stops in Greater London so the others would need to be added by conversion.
All the other data used by Google Maps have to be obtained from other sources. You can use the NaPTAN dataset to get the data from the other sources by searching for the unique ATCO code which is provided for every stop. As far as I know there is no single, free API for the entire country although services such as the TransportAPI are available at a price. The TfL API is excellent for its services in the London area. Likewise there are ample free sources of national rail information. Bus and metro data for specific towns/counties/regions can be found on a wide variety of websites provided by the operators, local authorities, etc. I have no idea which of those provide a free API similar to TfL. Even if they exist, finding and using the correct API for every UK stop would be a mammoth task. I assume Google builds and maintains its own databases, either by scraping the websites or by cooperating with the owners.
Practically, yes. The data that you want is also in the TNDS and BODS datasets, in the same XML format, alongside all the other information that these provide.
The heart of the problem is that this is a complex set of data, with varying structures, depending on the type of stop point.
I have a parsed version of this week’s NaPTAN xml file to give you a feeling for the actual structure, as a simple txt file. Unfortunately, this forum only allows images to be uploaded. If you PM me, I can send it to you