Simplify geometries in OpenStreetMap PBF files using the Osmium Library and the Douglas-Peucker algorithm from libGEOS.
This tool reduces the geometric complexity of OSM data, typically resulting in geometries that use around 20% fewer nodes, while keeping all original nodes in the file, though some become unused.
Nodes at the start or end of ways, or shared by multiple ways, or with tags are always preserved in the simplified version.
Note: The resulting PBF file size usually remains nearly the same.
This simplification is especially useful when you want to reduce geometry precision before processing OSM data with other tools. Like in OSRM to reduce disk and memory usage by about 20%.
mkdir build && cd build
cmake ..
make./osm-pbf-simplify input.osm.pbf <EPSG-code> <tolerance> output.osm.pbf- EPSG-code — Target projection (e.g.,
2154for Lambert-93). - tolerance — Simplification tolerance in projection units (e.g., meters).
It is recommended to select a projection that uses meters or similar units, so the tolerance value is consistent. If unsure, use a suitable UTM zone EPSG code, UTM coordinates are in meters.
The simplification is performed on projected coordinates using the Douglas–Peucker algorithm from libGEOS. A reimplementation that uses Haversine distance (on geographic coordinates) is welcome.
./osm-pbf-simplify andorra-latest.osm.pbf 2154 2 output.osm.pbf