Skip to main content

🗺️ osm-to-xodr

uv PyPI Python Version Tests License

Convert OpenStreetMap (.osm) files to OpenDRIVE (.xodr) using SUMO's netconvert with optimized defaults for driving simulators like CARLA.


✨ Features

  • 🎯 Sane Defaults: Pre-configured netconvert parameters optimized for realistic road networks
  • 🚦 Traffic Sign Support: Extracts and converts traffic signs to OpenDRIVE signals
  • ⚙️ Highly Configurable: Settings via CLI arguments, environment variables, or .env file
  • 🎨 Modern Python CLI: Built with Typer, Rich progress display, and Loguru logging
  • 🧩 Modular Architecture: Clean separation of concerns for easy maintenance

📋 Requirements

  • Python: 3.11 or higher ✅
  • SUMO: For netconvert command 🚗

Installing SUMO

Linux (Ubuntu/Debian):

# Stable release
sudo add-apt-repository ppa:sumo/stable
sudo apt-get update
sudo apt-get install sumo sumo-tools

# Or via Flatpak
flatpak install flathub org.eclipse.sumo

macOS / Linux:

brew tap dlr-ts/sumo
brew install sumo

Windows:

Download from SUMO Downloads

📦 Installation

Install from PyPI

# With uv (recommended)
uv tool install osm-to-xodr

# Or with pip
pip install osm-to-xodr

From Source

git clone https://github.com/RISE-Dependable-Transport-Systems/osm-to-xodr.git
cd osm-to-xodr
uv sync

🚀 Quick Start

1. Verify SUMO Installation

osm-to-xodr check

2. Convert Your First Map

# Basic conversion with optimized defaults
osm-to-xodr convert map.osm

# Custom output location
osm-to-xodr convert map.osm -o output/my_network.xodr

# Enable verbose logging
osm-to-xodr convert map.osm -v

3. (Optional) Generate Configuration Template

osm-to-xodr init-config

This creates a .env file with all available settings for customization.

CLI Reference

osm-to-xodr convert

Convert an OpenStreetMap file to OpenDRIVE format.

Usage: osm-to-xodr convert [OPTIONS] INPUT_FILE

Arguments:
  INPUT_FILE  Input OpenStreetMap (.osm) file

Options:
  -o, --output PATH              Output OpenDRIVE (.xodr) file
  -d, --output-dir PATH          Output directory [default: output]

  --lane-width FLOAT             Default lane width in meters [default: 3.5]
  --sidewalk-width FLOAT         Default sidewalk width [default: 2.0]
  --bikelane-width FLOAT         Default bike lane width [default: 1.5]
  --crossing-width FLOAT         Default crossing width [default: 4.0]

  --no-roundabouts               Disable roundabout guessing
  --no-ramps                     Disable ramp guessing
  --no-tls                       Disable traffic light guessing
  --no-sidewalks                 Don't import sidewalks
  --no-crossings                 Don't import crossings
  --no-turn-lanes                Don't import turn lanes
  --no-bike-access               Don't import bike access
  --keep-geometry                Don't simplify geometry
  --turnarounds                  Enable turnaround connections

  -k, --keep-intermediate        Keep intermediate files
  -v, --verbose                  Enable verbose output
  -V, --version                  Show version

osm-to-xodr check

Check if netconvert is available and show version information.

osm-to-xodr init-config

Generate a template .env configuration file with all available settings.

⚙️ Configuration

Settings can be configured via:

  1. CLI arguments (highest priority)
  2. Environment variables with OSM_TO_XODR_ prefix
  3. .env file in the current directory

Environment Variables

# Lane dimensions
OSM_TO_XODR_LANE_WIDTH=3.5
OSM_TO_XODR_SIDEWALK_WIDTH=2.0
OSM_TO_XODR_BIKELANE_WIDTH=1.5
OSM_TO_XODR_CROSSING_WIDTH=4.0

# Feature flags
OSM_TO_XODR_GUESS_ROUNDABOUTS=true
OSM_TO_XODR_GUESS_RAMPS=true
OSM_TO_XODR_GUESS_TLS_SIGNALS=true
OSM_TO_XODR_IMPORT_SIDEWALKS=true
OSM_TO_XODR_IMPORT_CROSSINGS=true
OSM_TO_XODR_IMPORT_TURN_LANES=true
OSM_TO_XODR_IMPORT_BIKE_ACCESS=true
OSM_TO_XODR_REMOVE_GEOMETRY=true
OSM_TO_XODR_NO_TURNAROUNDS=true

# Application settings
OSM_TO_XODR_OUTPUT_DIR=output
OSM_TO_XODR_TMP_DIR=tmp
OSM_TO_XODR_KEEP_INTERMEDIATE=false
OSM_TO_XODR_VERBOSE=false

📁 Project Structure

osm-to-xodr/
├── src/osm_to_xodr/
│   ├── __init__.py      # Package metadata
│   ├── cli.py           # Typer CLI interface
│   ├── config.py        # Pydantic settings
│   ├── converter.py     # Main orchestration
│   ├── netconvert.py    # SUMO subprocess wrapper
│   └── postprocess.py   # Signal conversion
├── data/
│   ├── osm/             # Input OSM files
│   └── xodr/            # Output XODR files
├── tests/               # Pytest test suite
├── justfile             # Task runner
└── pyproject.toml       # Project configuration

🛠️ Development

Setup

# Clone repository
git clone https://github.com/RISE-Dependable-Transport-Systems/osm-to-xodr.git
cd osm-to-xodr

# Install with dev dependencies
uv sync --all-extras

# Install pre-commit hooks
uv run pre-commit install

Task Runner (just)

# Show available commands
just

# Run linting
just lint

# Run tests
just test

# Run tests with coverage
just test-cov

# Format code
just fmt

# Run pre-commit on all files
just pre-commit

# Test conversion with sample file
just convert-test

# Full CI pipeline
just ci

Running Tests

# Run all tests
just test

# Run unit tests only
uv run pytest -m "not integration"

# Run integration tests (requires netconvert)
uv run pytest -m integration

# With coverage
uv run pytest --cov=osm_to_xodr --cov-report=html

🔧 Troubleshooting

❌ netconvert Not Found

🗺️ Conversion Errors

⚠️ Missing Road Features


🔍 How It Works

The conversion process has three steps:

  1. Extract Traffic Signs: First netconvert pass extracts traffic sign POIs from OSM
  2. Generate OpenDRIVE: Second pass creates the road network with signs as objects
  3. Post-process Signals: Python converts <object> elements to proper <signal> elements for CARLA compatibility

📄 License

MIT License - See LICENSE for details.

🙌 Credits

  • SUMO - Simulation of Urban Mobility
  • OpenDRIVE - ASAM OpenDRIVE standard

Metadata

Release files for osm-to-xodr 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osm-to-xodr 0.3.0
File Size Uploaded Provenance Actions
osm_to_xodr-0.3.0.tar.gz 5.9 MB Without provenance Details for osm_to_xodr-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for osm-to-xodr 0.3.0
File Interpreter ABI Platform Actions
osm_to_xodr-0.3.0-py3-none-any.whl Python 3 none any Details for osm_to_xodr-0.3.0-py3-none-any.whl

Total release size: 5.9 MB

Release files / osm_to_xodr-0.3.0.tar.gz

Download URL osm_to_xodr-0.3.0.tar.gz
Size 5.9 MB
Tags Source
SHA-256 checksum
How to use checksums
42ce1b7a2446b25630c6274530ebaab4290bdf5928cfc6dffc6a224dc0e450b6
BLAKE2b-256 checksum
How to use checksums
a4ec07ca70d091817cd73c2e9bd4948fc243a9a752f962f0da4dde6000ccfa45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / osm_to_xodr-0.3.0-py3-none-any.whl

Download URL osm_to_xodr-0.3.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d38056db9dc822063527170bd24c7acff7fc9ecf1f2a932b676289837221c0cb
BLAKE2b-256 checksum
How to use checksums
c53ae9ff963b1bccbd82bd57588b46400183915fbd53558a2734b46282cc14e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for osm-to-xodr 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page