Java Library to read and transform osm.pbf files

I have taken a look at the section Processing OpenStreetMap data on https://wiki.openstreetmap.org/wiki/Frameworks but have not found what I have in mind. Does anyone use a JAVA library to write programs that

  • open osm pbf files (e.g. berlin.osm.pbf)
  • apply filters (e.g. select all way elements with highway=primary)
  • transform tags (e.g. remove all tags with maxspeed=3)
  • save modified osm files (e.g. berlin-modified.osm.pbf)

The pbf format came together with java code to read and write it. Several programs use it, e.g. JOSM, mkgmap or splitter. Manipulation is a different story, the data structures needed for that depend on the wanted features. Therefore, the normal approach is to copy the data from pbf structures into special program structure, manipulate the data in the special structure and then transform again to pbf structure.
See https://wiki.openstreetmap.org/wiki/PBF_Format#The_code

Thanks GerdP.

Does anyone have experience with osm4j?

http://jaryard.com/projects/osm4j/tutorial/index.html

I do, can recommend it. :slight_smile:

I’m using osm4j to read OSM data in various formats for 3d rendering. For my purposes, I sometimes wish it was a bit higher-level, but it seems robust, has a nice tutorial, and works as advertised. Should meet the requirements of your use case well!

(Another option would be osmosis. Unfortunately, it lacks an active maintainer, so its future is uncertain.)