Skip to content

datasciencecampus/graphite

Repository files navigation

G R A P H I T E

graphite [origin: german] noun Definitions:

  1. a very common mineral, soft native carbon, occurring in black to dark-gray foliated masses, with metallic luster and greasy feel: used for pencil leads, as a lubricant, and for making crucibles and other refractories; plumbago; black lead;
  2. to write, draw

Contents

Introduction

This repository shows how you can build an OpenTripPlanner server locally using a Java Virtual Machine (JVM) or Docker.

Software Prerequisites

  • For GTFS building (optional)
    • A C# compiler such as Visual Studio Code, AND
    • MySQL
  • For OTP server (required)

GTFS feed

An OpenTripPlanner server can be built without a General Transit Feed Specification (GTFS) dataset. However, a GTFS feed is required to analyse public transport. Without it you can analyse car, bicycle, and foot transport using OpenStreetMap (OSM) data.

Sample GTFS data

The Data Science Campus has created some cleaned GTFS data from March 2019 (using the guide here) for:

The Data Science Campus has also created a bespoke OpenStreetMap (osm) file for Cardiff, Wales, UK for March 2019:

OSM files for all other regions can be downloaded from geofabrik.

Note: these GTFS do not contain the most recent timetables, it is only designed as a practice set of GTFS data for use with the propeR tool. Some (but not most) services have end dates of 2018-08-15, 2018-09-02, 2018-10-31. Therefore, analysing journeys after these dates will not include these services. Most services have an end date capped at 2020-01-01.

Creating and running an OpenTripPlanner server

Java method

OpenTripPlanner (OTP) is an open source multi-modal trip planner, which runs on Linux, Mac, Windows, or potentially any platform with a JVM. More details, including basic tutorials can be found here. Guidance on how to setup the OpenTripPlanner locally can be found here. Here is the method that worked for us:

  1. Check you have the latest java SE runtime installed on your computer, preferrably the 64-bit version on a 64-bit computer. The reason for this is that the graph building process in step 7 uses a lot of memory. The 32-bit version of java might not allow a sufficient heap size to be allocated to graph and server building. For the GTFS sample data [here](add link), a 32-bit machine may suffice.

  2. Create an 'otp' folder in a preferred root directory.

  3. Download the latest single stand-alone runnable .jar file of OpenTripPlanner here. Choose the '-shaded.jar' file. Place this in the 'otp' folder.

  4. Create a 'graphs' folder in the 'otp' folder.

  5. Create a 'default' folder in the 'graphs' folder.

  6. Put the GTFS ZIP folder(s) in the 'default' folder along with the latest OpenStreetMap .osm data for your area, found here. If you're using the sample GTFS data, an .osm file for Cardiff can be found here.

  7. Build the graph by using the following command line/terminal command whilst in the 'otp' folder:

    java -Xmx4G -jar otp-1.3.0-shaded.jar --build graphs/default
    

changing the shaded.jar file name and end folder name to be the appropriate names for your build. '-Xmx4G' specifies a maximum heap size of 4G memory, graph building may not work with less memory than this.

  1. Once the graph has been build you should have a 'Graphs.obj' file in the 'graphs/default' folder. Now initiate the server using the following command from the 'otp' folder:

    java -Xmx4G -jar otp-1.3.0-shaded.jar --graphs graphs --router default --server
    

Again, checking the shaded.jar file and folder names are correct.

  1. If successful, the front-end of OTP should be accessible from your browser using http://localhost:8080/.

Docker method

For convenience we have created several docker images to run an OTP server for several regions in the UK. First you must install Docker. To run, type in the command line (parse -d flag to daemonise):

docker run -p 8080:8080 datasciencecampus/dsc_otp:<tag_number>

where <tag_number> is:

If successful, the front-end of OTP should be accessible from your browser using http://localhost:8080/.

Killing a Docker container

To kill a docker container first list all containers running using:

docker ps

Then:

docker stop <container_ID>

Building your own Docker container

A stand-alone OTP server can also be built and deployed in the docker/ directory by editing the Dockerfile and build.sh files, then cd to the docker folder containing the a Dockerfile and use the command line:

docker build . -t <tag_name>

The uploaded Dockerfile has the following arguments that can be passed to docker build using --build-arg:

  • HEAP (the heap size of the JVM, default is 16GB, you may need over 32GB for a UK build)
  • REG (the region, here set to 1 for Wales, 2 for Scotland, 3 for England, and 4 for UK)
  • OTP_JAR (the OTP jar file version, here set to 1.3.0 by default)

Then run the created image using:

docker run -p 8080:8080 <tag_name>

FAQ

Q: Do I need an OpenStreetMap (.osm) file to build a graph?

A: Yes, whilst you can build the graph without an .osm file. You will need it to analyse the graph.

Q: Do I need a GTFS file to build a graph?

A: An OpenTripPlanner server can be built without a General Transit Feed Specification (GTFS) dataset. However, a GTFS feed is required to analyse public transport. Without it you can analyse car, bicycle, and foot transport using OpenStreetMap (OSM) data.

Q: I found a bug!

A: Please use the GitHub issues form to provide us with the information.

Authors / Contributors

Data Science Campus - Office for National Statistics

Contributions and Bug Reports

We welcome contributions and bug reports. Please do this on this repo and we will endeavour to review pull requests and fix bugs in a prompt manner.

Licence

The Open Government Licence (OGL) Version 3

Copyright (c) 2018 Office of National Statistics

This source code is licensed under the Open Government Licence v3.0. To view this licence, visit www.nationalarchives.gov.uk/doc/open-government-licence/version/3 or write to the Information Policy Team, The National Archives, Kew, Richmond, Surrey, TW9 4DU.