Extract OpenStreetMap PBF sub-regions from country-level data using a bounding box.
- Docker and Docker Compose
-
Clone the repository
git clone https://github.com/trufi-association/trufi-pbf-extractor.git cd trufi-pbf-extractor -
Create your configuration
cp .env.example .env
-
Edit
.envwith your city's values (see Configuration section below) -
Run the extractor
docker-compose up --build
-
Find your output in
./data/<city_name>.osm.pbf
Edit the .env file with these variables:
| Variable | Description | Example |
|---|---|---|
CITY_NAME |
Name for the output file | kigali |
BBOX |
Bounding box (west,south,east,north) | 29.979526,-2.079821,30.27987,-1.779581 |
GEOFABRIK_URL_PATH |
Path to country PBF on Geofabrik | /africa/rwanda-latest.osm.pbf |
Bounding Box:
- Go to boundingbox.klokantech.com
- Navigate to your city and draw a box around the area you want
- Select "CSV" format at the bottom
- Copy the coordinates (format: west,south,east,north)
Geofabrik URL Path:
- Go to download.geofabrik.de
- Navigate to your continent → country
- Copy the path after
download.geofabrik.de(e.g.,/africa/rwanda-latest.osm.pbf)
CITY_NAME=kigali
BBOX=29.979526,-2.079821,30.27987,-1.779581
GEOFABRIK_URL_PATH=/africa/rwanda-latest.osm.pbfCITY_NAME=quito
BBOX=-78.669528,-0.416925,-77.958163,0.504543
GEOFABRIK_URL_PATH=/south-america/ecuador-latest.osm.pbfCITY_NAME=cochabamba
BBOX=-66.227,-17.478,-66.086,-17.329
GEOFABRIK_URL_PATH=/south-america/bolivia-latest.osm.pbfThe extracted PBF file will be saved to:
./data/<CITY_NAME>.osm.pbf
You can use this file with:
- OpenTripPlanner for transit routing
- JOSM for viewing/editing
- Other OSM-compatible tools
# Check if Docker is running
docker ps
# Start Docker Desktop or the Docker daemon# Create the data folder with proper permissions
mkdir -p data
chmod 755 data- Check your internet connection
- Verify the Geofabrik URL path is correct at download.geofabrik.de
- Verify your bounding box coordinates are correct
- Make sure west < east and south < north
- Check that your bbox is within the country boundaries
- Downloads the country-level PBF from Geofabrik
- Uses osmium-tool to extract the specified bounding box
- Saves the result to the mounted data volume
MIT License - see LICENSE for details.
- Trufi Association
- Geofabrik for OpenStreetMap extracts
- osmium-tool for PBF processing