Interactive CLI tool to download and process OpenStreetMap data for OSRM routing services
npm install osrm-map-data-setup



An interactive, user-friendly bash script to download and process OpenStreetMap data for OSRM (Open Source Routing Machine) routing services.
Perfect for developers building route optimization, navigation apps, logistics platforms, or any application requiring offline routing capabilities.
---
- π Global Coverage - Access 180+ countries across all continents
- π¨ Beautiful Interactive UI - Intuitive menu system with color-coded navigation
- π Parallel Downloads - Download multiple regions simultaneously
- π Auto-Retry Logic - Robust download handling with exponential backoff
- βοΈ Automated Processing - Automatic OSRM graph extraction, partitioning, and customization
- π₯ Health Checks - Built-in verification to ensure routing service is ready
- π Progress Tracking - Real-time feedback on download and processing status
- π³ Docker-Ready - Seamless integration with Docker-based OSRM deployments
- πΎ Resume Support - Continue interrupted downloads automatically
---
- Route Optimization - Build logistics and delivery route planning systems
- Navigation Apps - Create offline-capable navigation applications
- Geospatial Analysis - Analyze road networks and accessibility
- Location Services - Develop location-based services with routing
- Research Projects - Academic research on transportation and urban planning
- Ride-Sharing Platforms - Calculate optimal routes for drivers
- Fleet Management - Optimize vehicle routing for fleet operations
---
- Bash 5.0+ (comes pre-installed on macOS and most Linux distributions)
- Docker - Install Docker
- curl or wget - For downloading map data
- Disk Space - Varies by region (10GB - 100GB+ for large countries/continents)
#### Option 1: NPM (Recommended)
``bashInstall globally
npm install -g osrm-map-data-setup
#### Option 2: Clone Repository
`bash
Clone the repository
git clone https://github.com/mahdialavitabar/osrm-map-data-setup.git
cd osrm-map-data-setupMake the script executable
chmod +x setup-osrm.shRun the interactive menu
./setup-osrm.sh
`#### Option 3: Programmatic API (Node.js)
`javascript
const osrm = require('osrm-map-data-setup');// Download and process Germany
await osrm.setup({
regions: ['germany'],
dir: './osrm-data',
profile: 'car',
});
// Download only (no processing)
await osrm.download(['france', 'spain'], './osrm-data');
// Process existing files only
await osrm.process(['germany'], { profile: 'bicycle' });
// Check dependencies
const deps = osrm.checkDependencies();
console.log(deps); // { bash: true, docker: true, curl: true, wget: false }
`$3
#### Interactive Mode (Recommended)
Simply run the script without arguments to launch the interactive menu:
`bash
./setup-osrm.sh
`Navigate through the beautiful menu to:
1. Select a continent
2. Choose specific countries or download entire regions
3. Add multiple selections
4. Download and process automatically
#### Command-Line Mode
For automation, scripts, or CI/CD pipelines:
`bash
Single country
./setup-osrm.sh iranMultiple countries
./setup-osrm.sh germany france spainEntire continent
./setup-osrm.sh europeMix and match
./setup-osrm.sh japan south-korea europe/monaco us-westCustom Geofabrik paths
./setup-osrm.sh europe/germany/berlin
`---
π How It Works
$3
The script downloads
.osm.pbf (Protocolbuffer Binary Format) files from Geofabrik, a reliable source for OpenStreetMap extracts.$3
Using Docker containers, the script processes the raw OSM data through three OSRM stages:
- Extract - Converts OSM data to routing graph
- Partition - Optimizes graph structure for fast queries
- Customize - Applies routing profiles (e.g., car, bike, foot)
$3
Renames processed files to the standard
map.osrm format for Docker Compose integration.$3
Validates the routing service by performing test route calculations.
---
π Project Structure
`
osrm-map-data-setup/
βββ setup-osrm.sh # Main setup script
βββ README.md # This file
βββ LICENSE # MIT License
βββ CONTRIBUTING.md # Contribution guidelines
βββ .gitignore # Git ignore patterns
βββ examples/
β βββ docker-compose.yml # Example Docker Compose configuration
β βββ api-usage.md # OSRM API usage examples
βββ osrm/ # Output directory (created by script)
βββ map.osrm* # Processed routing data
βββ downloads/ # Downloaded .osm.pbf files
`---
π Supported Regions
$3
- π Africa (58 countries)
- π§ Antarctica (whole continent)
- π Asia (37 countries)
- π¦ Australia & Oceania (5 countries)
- π΄ Central America (6 countries)
- π° Europe (49 countries)
- π½ North America (9 regions)
- π» Russia (whole country)
- π South America (11 countries)
π View Full Country List
#### Africa
algeria, angola, benin, botswana, burkina-faso, burundi, cameroon, canary-islands, cape-verde, central-african-republic, chad, comores, congo-brazzaville, congo-democratic-republic, djibouti, egypt, equatorial-guinea, eritrea, ethiopia, gabon, gambia, ghana, guinea, guinea-bissau, ivory-coast, kenya, lesotho, liberia, libya, madagascar, malawi, mali, mauritania, mauritius, morocco, mozambique, namibia, niger, nigeria, reunion, rwanda, saint-helena-ascension-and-tristan-da-cunha, sao-tome-and-principe, senegal, seychelles, sierra-leone, somalia, south-africa, south-sudan, sudan, swaziland, tanzania, togo, tunisia, uganda, zambia, zimbabwe
#### Asia
afghanistan, armenia, azerbaijan, bangladesh, bhutan, cambodia, china, gcc-states, india, indonesia, iran, iraq, israel-and-palestine, japan, jordan, kazakhstan, kyrgyzstan, laos, lebanon, malaysia-singapore-brunei, maldives, mongolia, myanmar, nepal, north-korea, pakistan, philippines, south-korea, sri-lanka, syria, taiwan, tajikistan, thailand, turkmenistan, uzbekistan, vietnam, yemen
#### Australia & Oceania
australia, fiji, new-caledonia, new-zealand, papua-new-guinea
#### Central America
belize, cuba, guatemala, haiti-and-domrep, jamaica, nicaragua
#### Europe
albania, andorra, austria, azores, belarus, belgium, bosnia-herzegovina, bulgaria, croatia, cyprus, czech-republic, denmark, estonia, faroe-islands, finland, france, georgia, germany, great-britain, greece, hungary, iceland, ireland-and-northern-ireland, isle-of-man, italy, kosovo, latvia, liechtenstein, lithuania, luxembourg, macedonia, malta, moldova, monaco, montenegro, netherlands, norway, poland, portugal, romania, serbia, slovakia, slovenia, spain, sweden, switzerland, turkey, ukraine
#### North America
canada, greenland, mexico, us, us-midwest, us-northeast, us-pacific, us-south, us-west
#### South America
argentina, bolivia, brazil, chile, colombia, ecuador, paraguay, peru, suriname, uruguay, venezuela
---
π³ Docker Integration
$3
Create a
docker-compose.yml file:`yaml
version: '3.8'services:
osrm:
image: osrm/osrm-backend
container_name: osrm-routing
ports:
- '5000:5000'
volumes:
- ./osrm:/data
command: osrm-routed --algorithm mld /data/map.osrm
restart: unless-stopped
`$3
`bash
After running setup-osrm.sh
docker-compose up -dTest the routing API
curl 'http://localhost:5000/route/v1/driving/13.388860,52.517037;13.397634,52.529407?overview=false'
`---
π§ Configuration
$3
Customize behavior by setting these variables before running the script:
`bash
Maximum download retry attempts (default: 3)
export MAX_RETRIES=5Initial retry delay in seconds (default: 5)
export RETRY_DELAY=10Custom output directory (default: ./osrm)
export OSRM_DIR="/path/to/custom/directory"
`$3
`bash
Process only, skip download (if you already have .osm.pbf files)
SKIP_DOWNLOAD=1 ./setup-osrm.sh iranSpecify custom OSRM profile
OSRM_PROFILE=bicycle ./setup-osrm.sh netherlands
`---
π Disk Space Requirements
Approximate disk space needed (varies by region density):
| Region Type | Raw OSM Data | Processed OSRM | Total |
| -------------- | ------------ | -------------- | ---------- |
| Small Country | 50-200 MB | 100-500 MB | 150-700 MB |
| Medium Country | 200-1 GB | 500 MB-2 GB | 1-3 GB |
| Large Country | 1-5 GB | 2-10 GB | 5-15 GB |
| Continent | 5-30 GB | 10-60 GB | 20-100 GB |
Examples:
- Monaco: ~20 MB total
- Germany: ~3 GB total
- USA: ~15 GB total
- Europe: ~50 GB total
- Planet: ~100+ GB total
---
π§ͺ Testing the Setup
After successful setup, test your OSRM instance:
$3
`bash
Replace coordinates with locations within your map region
curl 'http://localhost:5000/route/v1/driving/LON1,LAT1;LON2,LAT2?overview=false'
`$3
`bash
curl 'http://localhost:5000/table/v1/driving/LON1,LAT1;LON2,LAT2;LON3,LAT3'
`$3
`bash
curl 'http://localhost:5000/nearest/v1/driving/LON,LAT'
`See OSRM API Documentation for complete API reference.
---
π Troubleshooting
$3
Issue: Network timeouts or failed downloads
`bash
Increase retry attempts
export MAX_RETRIES=10
./setup-osrm.sh iran
`$3
Issue: Docker socket permission errors
`bash
Add user to docker group
sudo usermod -aG docker $USER
Log out and back in
`$3
Issue: Insufficient space for large regions
`bash
Check available space
df -hClean Docker cache
docker system prune -aUse external drive
export OSRM_DIR="/Volumes/ExternalDrive/osrm"
`$3
Issue: Memory issues on large datasets
`bash
Increase Docker memory limit in Docker Desktop settings
Recommended: 4GB+ for large countries, 8GB+ for continents
`$3
Issue: Test coordinates outside map area
- Ensure test coordinates are within the downloaded region
- Use coordinates from major cities in your region
---
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
$3
`bash
Fork the repository
git clone https://github.com/mahdialavitabar/osrm-map-data-setup.git
cd osrm-map-data-setupCreate a feature branch
git checkout -b feature/amazing-featureMake your changes and test
./setup-osrm.shCommit and push
git commit -m "Add amazing feature"
git push origin feature/amazing-feature
``---
This project is licensed under the MIT License - see the LICENSE file for details.
---
- OpenStreetMap Contributors - For the incredible map data
- Geofabrik - For providing reliable OSM extracts
- Project OSRM - For the amazing routing engine
- OSRM Backend - For the Docker images and tools
---
- OSRM Documentation
- OpenStreetMap Wiki
- Geofabrik Download Server
- OSRM Demo
---
If this project helped you, please consider:
- β Starring the repository
- π Reporting bugs and requesting features via Issues
- π€ Contributing improvements via Pull Requests
- π’ Sharing with others who might find it useful
---
Made with β€οΈ by developers, for developers