Host OpenStreetMap yourself

OpenStreetMap (OSM) is a free world map that is created jointly by people all over the world - free, open and independent. While Google Maps, as the market leader, is often the first choice for digital maps, OSM relies on a completely different principle: a collaborative community that collects, improves and makes geographical data available free of charge.


Why is this important? Because maps are knowledge – and knowledge should be free. For individual applications, it can make sense to host OSM data yourself in order to develop customized map solutions and retain control over the data and its presentation. Self-hosting OSM offers several advantages:

  • Independence: You are not dependent on external services and have full control over the card data.
  • Adaptability: You can customize the map styling and the data displayed according to your own needs.
  • Data protection: All data is locally self-hosted. No external APIs are accessed.

There are two main methods for displaying maps:

  • Grid tiles: Pre-made image files for different zoom levels. They are easy to implement but offer less flexibility in customizing the map style.
  • Vector tiles: Contains geographic data in the form of vectors (points, lines, polygons) that are rendered on the client side. This allows flexible adjustments to the map design and a sharp display at all zoom levels. However, rendering requires more computing power on the client device.

Vector tiles are particularly suitable for self-hosting, as they offer more customization options and are more efficient. For regional maps with smaller areas, ~1 GB of hard disk space is often sufficient. It makes sense to use SSDs, as they have speed advantages when loading the tiles. Static vector tiles do not require a running map server (e.g. TileServer GL or Mapnik), have less maintenance effort and less server load - they are ideal for smaller projects with fixed map sections.

My little package osmhelper facilitates the process of creating and deploying vector tiles from .osm.pbfFiles. Using custom bounding boxes, developers can extract specific geographic areas and generate matching boilerplate files that can be uploaded directly to a server. This makes integrating OSM data into web projects much easier. To use osmhelper, some preparation is required. The library builds on tools such as osmium, mbutil and tilemaker that must be installed.

Installation of osmium

osmium is a powerful tool for processing OSM data.

mkdir osmium
cd osmium
wget https://github.com/osmcode/osmium-tool/archive/refs/tags/v1.16.0.tar.gz
tar -xzf v1.16.0.tar.gz
cd osmium-tool-1.16.0
apt-get install libosmium2-dev libprotozero-dev nlohmann-json3-dev libboost-program-options-dev libbz2-dev zlib1g-dev liblz4-dev libexpat1-dev cmake pandoc
mkdir build
cd build
cmake ..
make
make install
cd ..
cd ..
rm -rf ./osmium
exec env -i HOME=$HOME bash -l
osmium --version

Installation of mbutil

mbutil is a Python-based tool for working with MBTiles.

git clone https://github.com/mapbox/mbutil.git
cd mbutil
python setup.py install
cd ..
rm -rf ./mbutil
exec env -i HOME=$HOME bash -l
mb-util --version

Installation of tilemaker

tilemaker is an open source tool that converts OSM data directly into vector tiles.

apt install build-essential libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev lua5.1 liblua5.1-0-dev libshp-dev libsqlite3-dev rapidjson-dev
git clone https://github.com/systemed/tilemaker.git
cd tilemaker
make
make install
cd ..
rm -rf ./tilemaker
exec env -i HOME=$HOME bash -l
tilemaker --help

Download the conversion script

mkdir openstreetmap
cd openstreetmap
wget -O ./convert.sh https://raw.githubusercontent.com/vielhuber/osmhelper/refs/heads/master/convert.sh
chmod +x convert.sh

Using osmhelper

After installing the required tools, osmhelper can be used to generate vector tiles and prepare them for hosting:

./convert.sh \
    --url https://download.geofabrik.de/europe/germany-latest.osm.pbf \
    --lat-min 47.27 \
    --lon-min 8.97 \
    --lat-max 50.57 \
    --lon-max 13.84 \
    --compress

This process allows you to provide customized map sections efficiently and without the need for a dynamic map server. Integrating OpenStreetMap data into your own projects can be complex, especially when it comes to hosting and deployment. Since Google Maps has a monopoly on map solutions, many developers are looking for alternatives. osmhelper makes it easy to get started with hosting your own OpenStreetMap data. This gives you full control over your maps, no API restrictions and allows you to add your own data layers.

Most people know Google Maps as the standard solution for digital maps. But few know that OpenStreetMap is a great alternative - with no commercial restrictions or hidden costs. While Google Maps charges API usage fees and collects user data, OSM is free, open and supported by a global community. OSM is the Wikipedia of the map world - anyone can contribute, add streets, hiking trails or POIs (points of interest) and thus improve the free world map.

Back