Expand description

OpenRailwayMap Exporter

A library to fetch railway infrastructure data from an API, process it, and export the results.

The openrailwaymap_exporter crate is designed to help you work with railway infrastructure data. It provides an API client for fetching data, a railway model for representing and processing the data, and an export module for generating various output formats.

The primary modules included in the crate are:

  • railway_api_client: Contains the API client to fetch railway infrastructure data.
  • railway_model: Contains data structures and functions to work with the railway infrastructure data.
  • export: Provides functionality to export the railway data in different formats.
  • simulation: Handles the simulation components, including agent decisions, environment, and execution.
  • ai: Contains modules for the AI components, including reinforcement learning train agents and their state representation.
  • app: Provides a web application for displaying and interacting with the data (only available when targeting WebAssembly).

OpenRailwayMap Exporter

Github Repo Github Pages Build License: MIT codecov Doc Book Demo

A command-line tool built with Rust that fetches railway data from OpenRailwayMap using the Overpass API and exports it into a custom format.

Overview

Features

  • Downloads railway data using Overpass API
  • Retrieves railway track data including length, GPS path, IDs, connected elements, and switches
  • Accepts bounding box parameter to define the area for which data should be downloaded

Data will be downloaded from overpass-turbo.

Usage

Run the command-line tool using the following command structure:

cargo run -- --bbox "latitude_min,longitude_min,latitude_max,longitude_max"

For example, to download railway data within a bounding box around Frankfurt, use:

cargo run -- --bbox "49.9,8.4,50.2,8.8"

or use the following:

cargo run -- --area "Frankfurt am Main"

To save the elements in a json file, use the following:

cargo run -- --area "Frankfurt am Main" -j -o output.json

To save the graph as svg format use:

cargo run -- --area "Frankfurt am Main" -d -o output.dot

then you can convert the graphviz format into a svg image using the following command:

cargo run -- --area "Frankfurt am Main" --svg -o output.svg

Web App

  1. Compile the code to WASM:

    wasm-pack build --target web
    
  2. Run the Web version in your browser

    python3 -m http.server
    
  3. Open your browser on Localhost

3d App

cargo run --features app3d --example app3d

Running Tests

To run tests, use the following command:

cargo test

Running Benchmarks

To run benchmarks, use the following command:

cargo bench

Profiling with Flamegraph

To create a flamegraph for a specific example, first, make sure you have cargo-flamegraph installed:

cargo install flamegraph

Then, run the following command:

cargo flamegraph --dev --example vilbel

This will generate a flamegraph.svg for the vilbel example.

Python Bindings

This project includes Python bindings using PyO3 and Maturin. To use the Python bindings, follow these steps:

  1. Install the bindings in a virtual environment:

    pip install .
    
  2. Run the test file:

    python tests/pythonlib.py
    

Jupyter Notebook

A Jupyter notebook is available to demonstrate how to use the Python bindings and visualize the railway graph as an SVG image. You can access the notebook here.

Python API

The Python bindings provide a PyOverpassImporter class for importing railway graph data from a JSON string and a PyRailwayGraph class for working with the imported railway graph data. Here’s a brief overview of the available methods:

PyOverpassImporter
  • new(): Create a new PyOverpassImporter instance.
  • import_graph(input: str) -> PyResult<PyRailwayGraph>: Import railway graph data from a JSON string and return a PyRailwayGraph instance containing the imported data.
PyRailwayGraph
  • node_count() -> usize: Get the number of nodes in the railway graph.
  • edge_count() -> usize: Get the number of edges in the railway graph.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Re-exports

Modules

  • The ai module provides a reinforcement learning agent that controls a train in a railway network simulation.
  • A module containing algorithms for working with geographical data structures.
  • The app3d module provides functionality to visualize railway graphs in 3D.
  • Export module for the OpenRailwayMap Exporter.
  • A module containing exporters to various formats for RailwayGraph.
  • module for importers
  • This prelude re-exports the most commonly used items from the library.
  • This module provides Python bindings for importing and interacting with railway graphs.
  • Module railway_algorithms provides algorithms for working with railway networks.
  • Railway API Client module for the OpenRailwayMap Exporter.
  • Railway Model module for the OpenRailwayMap Exporter.
  • The railway_objects module contains traits for different types of railway objects, their positions within an internal model, target management, and geographical locations.
  • This module contains types related to railway simulations.
  • A module providing utility functions for calculating path lengths, remaining lengths, and the total length of a railway network.
  • Types used throughout the project.