Skip to main content

Convert OpenStreetMap (.osm) files to OpenDRIVE (.xodr) using SUMO netconvert with sane defaults

Project description

๐Ÿ—บ๏ธ 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

[!IMPORTANT] SUMO's netconvert is required for conversion. Choose your installation method below:

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

[!TIP] Use uvx to run the tool instantly without installation โ€” perfect for quick conversions:

uvx osm-to-xodr convert map.osm

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

[!NOTE] This command checks if netconvert is available and shows version information.

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

[!TIP] CLI flags take precedence over environment variables and .env file settings.

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

[!NOTE] Integration tests require SUMO's netconvert to be installed and available in your PATH.

๐Ÿ”ง Troubleshooting

โŒ netconvert Not Found

[!WARNING] If you see netconvert not found errors:

  • โœ… Verify SUMO is installed: netconvert --version
  • โœ… Check that SUMO's bin directory is in your PATH
  • โœ… On Linux, ensure you installed sumo not just sumo-tools

๐Ÿ—บ๏ธ Conversion Errors

[!TIP] If conversion fails:

  • Use --verbose flag to see detailed netconvert output
  • Check your OSM file is valid (open in JOSM or similar)
  • Try with --keep-intermediate to inspect intermediate .net.xml files
  • Reduce map complexity by focusing on smaller areas

โš ๏ธ Missing Road Features

[!NOTE] If converted roads are missing expected features:

  • Ensure your OSM data has proper road tags (check on OpenStreetMap.org)
  • Some features require specific flags (e.g., --no-sidewalks disables sidewalk import)
  • Use --keep-geometry to prevent road geometry simplification

๐Ÿ” 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osm_to_xodr-0.2.1.tar.gz (5.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osm_to_xodr-0.2.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file osm_to_xodr-0.2.1.tar.gz.

File metadata

  • Download URL: osm_to_xodr-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 MB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for osm_to_xodr-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b9d879af7712ac51684309773d92b445512cb145d4959e2e987ffe544312d7e2
MD5 d0ad63175771f7f045759656aeb92575
BLAKE2b-256 56c7e8876a415136ccb0201b3ec640123a9e93002869f0b9acc0534903b890b9

See more details on using hashes here.

File details

Details for the file osm_to_xodr-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: osm_to_xodr-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for osm_to_xodr-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf3d16f9c664b4752df7411e9dcc696324243b09a35fddb1ed8d5880ee654a0b
MD5 d96eb850746c00ae31c924ff3ef794a4
BLAKE2b-256 9d54809d3cc76a49e55009c38a523797e01eee5ef2b5dd7e0b307f3d4788aaeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page