OpenRailRouting

repository·master·Indexed 42 days ago

https://github.com/geofabrik/openrailrouting

A specialized railway routing engine based on a fork of GraphHopper. It utilizes OpenStreetMap data to provide routing that accounts for railway-specific constraints, including track gauge, voltage, frequency, and electrification types. The engine supports importing OSM data, serving an API and web interface, and performing map matching on GPX tracks.

Tokens
967
Snippets
4
Records
5
Agent score
3%

What's inside OpenRailRouting

  1. Define and use custom profiles

    master

    Profiles determine how the routing engine behaves (e.g., which tracks are accessible). Profiles consist of a name, turn_costs (including vehicle_types like train, light_rail, tram, subway and u_turn_costs), and custom_model_files.

    Custom model files are searched in src/main/resources/com/graphhopper/custom_profiles by default. You can specify an external directory for these models to avoid recompiling after changes:

    graphhopper:
      custom_models.directory: path/to/your/custom_models_directory
  2. Configure OpenRailRouting via YAML

    master
    OpenRailRouting is configured using a GraphHopper YAML configuration file. You can define graph locations, server ports, and encoded values here. For specific details on available keys, refer to the config.yml file in the repository root.
  3. Run the OpenRailRouting engine

    master

    The engine is executed via a JAR file using three primary actions: import, serve, and match.

    General Command Syntax:

    java -Xmx2500m -Xms50m \
      -Ddw.graphhopper.datareader.file=$OSMFILE \
      -jar target/railway_routing-0.0.1-SNAPSHOT.jar ACTION [ARGUMENTS] CONFIG_FILE [OPTARG]

    Actions

    1. import

    Imports OSM data into a graph stored in the graph-cache/ directory. Arguments:

    • --input, -i: Path to input .osm.pbf file.
    • --output, -o: Path to output directory for the graph.

    Required Settings (via -D or YAML):

    • graphhopper.datareader.file: Path to OSM file.
    • graphhopper.graph.location: Directory to write the graph (default: ./graph-cache).

    2. serve

    Starts an HTTP server for the API and web interface. Required Settings (via -D or YAML):

    • dw.graphhopper.datareader.file: Path to OSM file.
    • dw.graphhopper.graph.location: Path to the imported graph.
    • dw.server.applicationConnector.port: Port for the Jetty server.

    3. match

    Performs map matching on GPX tracks. Arguments:

    • --gpx-location=$PATTERN: Path to GPX file or wildcard pattern (e.g., --gpx-location="/path/*.gpx"). Results are saved as .res.gpx.
    • -V VEHICLE, --vehicle=$VEHICLE: The routing profile to use.

    Optional Arguments:

    • -a NUMBER, --gps-accuracy=NUMBER: GPS accuracy in metres (default: 40).
    • --max_nodes=NUMBER: Max nodes to visit between trackpoints (default: 10,000).
  4. Build OpenRailRouting from source

    master

    OpenRailRouting uses Maven for building. The repository includes a pre-built version of the web frontend, so NodeJS is not required for the build process. Use JUnit 5 for running unit tests.

    To build the project, initialize the submodules and run the Maven install command.

    git submodule init
    git submodule update
    mvn clean install
  5. Configure encoded values for railway attributes

    master

    To make specific railway attributes available for routing (e.g., in custom models), you must explicitly list them in the graph.encoded_values section of your configuration.

    Supported encoded values per edge include:

    • voltage: decimal (precision: 100 Volt)
    • frequency: decimal (precision: 2.5 Hz)
    • electrified: enum (UNSET, NO, OTHER, CONTACT_LINE, RAIL)
    • gauge: integer
    • railway_class: enum (RAIL, LIGHT_RAIL, TRAM, SUBWAY, NARROW_GAUGE, FUNICULAR)
    • railway_service: enum (NONE, SIDING, YARD, SPUR, CROSSOVER)
    • preferred_direction: boolean

    Example configuration:

    graphhopper:
      graph.encoded_values: gauge,voltage,electrified,frequency,road_environment,max_speed,rail_access,rail_average_speed,railway_class,railway_service