This vignette outlines how to produce GTFS timetables for the heavy rail network using ATOC CIF files.

Getting Data

Data for train timetables can be downloaded from the Rail Data Portal.

library(UK2GTFS)
nrdp_timetable("myfolder/timetable.zip")

Note that you need to register a free account with the Rail Data Portal. Any you need to set the NRDP_username and NRDP_password values in in your .Renviron file. You can use usethis::edit_r_environ() to easily access your .Renviron file. Remember to restart R after updating the file.

You can also use the nrdp_fares() and nrdp_routing() functions to download additional data.

Converting ATOC Data to GTFS

To do a simple conversion to GTFS, load the package, and use the atoc2gtfs function. The function requires the following arguments.

  • path_in is the file path to the ATOC timetable file, this comes a zipped folder with a name like ttis627.zip
  • ncores If > 1 then multicore processing is used to speed up the processing. Always leave one spare core for your OS.

A simple example is shown below:

path_in <- "myfolder/timetable.zip"
gtfs <- atoc2gtfs(path_in = path_in,
          ncores = 3)

Once the conversion has been completed, you can save the GTFS file.

gtfs_write(gtfs, 
           folder = "C:/GTFS",
           name = "gtfs_rail")

This will save the GTFS file to C:/GTFS/gtfs_rail.zip

Alternative Data Sources

CIF Files are available from Network Rail, the formatting is slightly different and so a separate function nr2gtfs() is provided.

Advanced features

The atoc2gtfs() function gives some customization options to how the GTFS file is built. It is also just a wrapper around other functions in the package. This section will explain the main steps.

Importing ATOC Data

After unzipping the folder, the reading of the ATOC data is done with the following functions:

Other files are currently ignored.

TIPLOC Locations

The timetable data refers to locations such as stations, junctions, etc. using a TIPLOC id. The locations of these are stored in the .msn file, but are not always accurate. Therefore the package comes with a tiplocs object which includes improved location data for TIPLOCS.

The additional locations and other additional data are managed by the UK2GTFS-data repo. Contributions of new or improved locations are welcome via pull request.

If you wanted to build using the locations included in the ATOC data, then you can use locations = "file" in atoc2gtfs() or manually build the stops using station2stops().

Agency

The data required to create the GTFS agency.txt file is not present in the ATOC CIF files. Therefore the package contains an example file instead. Contributions to this file are welcome via pull request.