Wednesday, 22 July 2009

National Rail (UK)

Some notes on the National Rail service in the UK which I'll be using to retrieve a list of stations and associated GPS co-ordinates.

Station Listing

CRS Codes, otherwise known as the 3 letter station codes, are available from this link. An example would be VIC for London Victoria. These codes save a bit of time when completing forms on their sites and are used for the SMS service as well as API calls.

Station Details

To obtain station details you would construct a URL such as http://www.nationalrail.co.uk/stations/<station_code>/localarea.html replacing <station_code> with the 3 letter CRS code from above. Nice bits you'll find in there include the latitude/longitude of the station. You'll need to screenscrape the details but it's easy enough to find:

<script type="text/javascript">
    addLoadEvent(function() { load(51.495261392, -0.1445405931, '')});
</script>

API

A SOAP interface is available from http://www.livedepartureboards.co.uk/ldbws/

Downloads

After a bit of experimenting with Python, BeautifulSoup and Google App Engine I've now got a .sql file which you can download that lists all the stations (as of 26 July 2009) with their names, codes and latitude and longitude. Download here