OpenStreetMap map size reduction guide
By: Jacek Czapla
Tags: Osm, Maps, Openstreetmap, Guides And Tutorials, Optimization

1. Download base map fragment

First, you need to decide what areas your map needs to cover. In this example, we will focus on western Germany. Germany’s full map will be the perfect base to extract from. There are a few possibilities to download the map. You can, for example, use https://protomaps.com/extracts (for small, user-defined fragments) or https://download.geofabrik.de (all kinds of predefined fragments).

In this guide, we will download a full map of Germany in .pbf format from Geofabrik.

If you can already find a map fragment on Geofabrik or Protomaps that is sufficient for your application, then you can skip the two following steps and go directly to step 4.

2. Prepare a boundary file

After getting a base map file we need to define the boundaries of our desired map fragment. The .poly file is exactly what we are looking for. It contains coordinates of boundary points. Since there is no single boundary file for regions Hessen, Niedersachsen, Nordrhein-Westfalen and Rheinland-Pfalz we need to create one. In order to do so, we will download .poly files for those regions and merge them in JOSM editor.

First, download .poly files from https://download.geofabrik.de/europe/germany.html for each of the regions. Below is an example of downloading the North Rhein-Westphalia .poly file.

Downloading .poly file for Nordrhein-Westfalen

In order to edit .poly files, you need JOSM with the poly plugin. Below you can see how to install the plugin.

Installing the “poly” plugin

The next step is to open all .poly files and merge them. See the example below.

Merge poly files and verify against map

Sometimes a manual adjustment is needed. For example, there can be some remaining points that should be deleted. You can verify if the selection is correct by using the background map. When everything is ready, save the new .poly file.

3. Extract map

Now that we have both .poly file with western Germany border and full Germany .pbf map, we can extract the desired fragment. In order to do so, we need the Osmosis command-line tool.

Open command line and type:

osmosis \

--read-pbf file="germany-latest.osm.pbf" \

--bp clipIncompleteEntities=true file="west-germany.poly" \

--write-pbf granularity=10000 file="west-germany.osm.pbf"

where:

--read-pbf file="germany-latest.osm.pbf" — chooses base map that we will extract from

--bp — extracts map fragment using .poly file. (full option --bounding-polygon )

clipIncompleteEntities=true — removes objects that are exactly on the borderline and would be incomplete after extraction

--write-pbf — choose output file

granularity=10000 — reduces map precision from 1.1cm to 1.1m (enough for navigation) and reduces the size by about 10%

As a result, we’ve obtained smaller map extract — instead of 3.4GB (whole Germany at the time of writing this text), we’ve got 1.2GB. Now let’s further decrease the size by removing unnecessary map objects.

4. Remove unnecessary map objects

Now that we have the desired .pbf map fragment we can proceed to remove map objects that are not required in our application.

To do this you need to learn about elements and tags in OpenStreetMap.