Use osmosis as a library in a java application

Hello.

I am trying to use osmosis into a java application (so as a lib). Unfortunately, there is no documentation whatsoever on how to do so and it is not trivial as osmosis seems to call a lot of different class layers to perform such an easy task as reading a pbf file… (it’s all abstracted behind plugin tasks so it is clearly not easy to go in for a newbee like me).
So is anyone on this forum, familiar with osmosis source code, that could help me by telling me how I can:

  • read an xml or pbf file
  • extract the information I want based on some tag values (for exemple, If I want to extract all ways of the type “highway” and their associated nodes, do osmosis keep a record of the nodes already parsed somewhere or do I have to read the osm file once again to extract the data for nodes associated to my highways? In the command line parametters, there is the “–used-nodes” option to do this but I couldn’t determine if in that case osmosis would read the osm file once again or if it had all the nodes already parsed recorded somewhere (in memory or in a temporary indexed file on disk)

Thanks

I’ve not used it, but https://wiki.openstreetmap.org/wiki/Osmium at least advertises and documents its use as a library.

Osmosis (java) and Osmium (C++) are two complete different things…

Indeed, but they do both do (or are advertised to do) some of the same things.

For parsing the xml or pbf file, check my old answer on help and the forum post linked there:

https://help.openstreetmap.org/questions/20695/lib-for-java-obf-pbf-or-other-format

You can chain this together with other functionality (Osmosis is essentially a pipeline of sequential processing steps). One of those should be tag-based filtering, although I haven’t done that yet myself. I’m going to have a look at the code, maybe I can figure it out.