Skip to content

Instantly share code, notes, and snippets.

@mikaelhg
Last active September 7, 2022 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelhg/2ec508b355398812fcb50d9da2d7603b to your computer and use it in GitHub Desktop.
Save mikaelhg/2ec508b355398812fcb50d9da2d7603b to your computer and use it in GitHub Desktop.
Generate static, Helsinki only map tiles from OpenStreetMap data
# Bounding box from http://norbertrenner.de/osm/bbox.html
HELSINKI_BBOX=24.577,60.079,25.228,60.335
# OpenStreetMap extract file from Geofabrik
wget https://download.geofabrik.de/europe/finland-latest.osm.pbf
# Cut the 500 MB Finland data file into a 34 MB Helsinki data file
# as this is much faster than using the import bbox.
osmconvert finland-latest.osm.pbf -b="$HELSINKI_BBOX" --out-pbf >helsinki.pbf
docker volume create openstreetmap-data
docker run --rm -it -e THREADS=8 \
-v `pwd`/helsinki.pbf:/data.osm.pbf \
-v openstreetmap-data:/var/lib/postgresql/12/main \
overv/openstreetmap-tile-server import
# The result is a 1.7 GB PostgreSQL data directory. Consider putting the volume on /dev/shm instead.
docker volume create openstreetmap-data
docker run -it --rm --name=osm -p 80:80 -e THREADS=4 \
-v openstreetmap-data:/var/lib/postgresql/12/main \
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
overv/openstreetmap-tile-server run
docker exec -it osm render_list -a -z 4 -Z 13 -n 4 -m ajt
@mikaelhg
Copy link
Author

@mikaelhg
Copy link
Author

mikaelhg commented Jun 17, 2021

Generating tiles without PostGIS with t-rex

https://xycarto.com/2021/04/30/static-vector-tiles-ii-openlayers-with-custom-projection/

Converting to the GDAL GPKG (sqlite3) format:

ogr2ogr -f GPKG helsinki.gpkg helsinki.pbf
xz --threads=0 -fkv helsinki.gpkg

docker run -v `pwd`/helsinki.gpkg:/tmp/helsinki.gpkg:ro sourcepole/t-rex genconfig --datasource /tmp/helsinki.gpkg
docker run -p 6767:6767 -v `pwd`/helsinki.gpkg:/var/data/in/helsinki.gpkg:ro -v `pwd`/helsinki_gpkg.toml:/var/data/in/myconfig.toml:ro sourcepole/t-rex serve --bind=0.0.0.0 --openbrowser=false --config=myconfig.toml

@mikaelhg
Copy link
Author

mikaelhg commented Sep 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment