Hi I'm new to OSM and Libosmium. My goal is to filter certain POI e.g. all the libraries worldwide with the location and certain tags and store it as a json to later processing (e.g. search nearest library). As source file sI use OSM extracts from http://download.geofabrik.de/ To be able to process it locally I started to look into Libosmium even though I'm a newbie with cpp. I'm using Ubuntu 20.04 and was able to compile Libosmium (which was already great).
Under /examples/ I found a pretty close example 1) How can I filter on
Is there a way to query amentiy=libray within the first line?
2) Is there a way to loop through all available fields e.g. for nodes I want to extract as well not only "name" + "location (lat, lon)", but also e.g. id, addr:country, addr:city, addr:street, addr:housenumber, ... 3) Instead of printf() of -> How would I adopt it to instead of print store it in a json or similar format? What I found was e.g. the proposal to use a map in combination with a tuple and a vector.
Not sure if this is the best way to be used with Libosmium (or put different how should I replace Thank you very much asked 09 Aug '22, 13:08 Muran123 |
@Jochen: Thank you very much for your answer. I like you proposed approach and I followed on it. a) Thanks to the amazing "osmium command line tool" I was able to quickly filter the pbf file for amenity=library (I only extended the filter to also include ways and relations with "nwr/" instead of "n/" only for nodes. b) For the further processing I already tried to use PyOsium before and was struggling to get it working to extract tags and store them (https://github.com/osmcode/pyosmium/issues/208). I was trying to follow the recommendations in https://github.com/osmcode/pyosmium/blob/master/doc/intro.rst but I keep getting "RuntimeError: Node callback keeps reference to OSM object. This is not allowed." That's the reason why I started to try to do it with Libosmium, because I was stuck with this error in python. When I try to run it with the following python program (which is a copy of the example from 2 like mentioned in the github issue 1, adopted for "amenity=library" and with the file http://download.geofabrik.de/europe/germany-latest.osm.pbf from Geofabrik.
I get the first 2 entries Stadtbibliothek Weinheim Deutsche Nationalbibliothek appended to the list (and also print out) and afterwards the program stops with "Node callback keeps reference to OSM object. This is not allowed." My technical set-up: Ubuntu 20.04, Python 3.8.10, IDE PyCharm 2022.2 May I ask you, if you could help me with what is going wrong in the python program? Thank you very much answered 10 Aug '22, 17:14 Muran123 |
Rather than learning C++ for this project and especially because you are already familiar with Python I suggest the following approach: Use the osmium command line tool to do a rough filtering of the input, for instance with To answer your questions (somewhat): 1. The approach you are using is correct, 2. You can loop over all tags with answered 10 Aug '22, 08:05 Jochen Topf |