This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How do I get the class and type of an osm-object returned from osmium parser ?

0

Hello.

I am using node-osmium for parsing a .pbf file. It works pretty well but I am missing some information: class and type of the osm-object e.g. class=amenity, type=parking

These are available in objects I get e.g with overpass or nominatim.

My question ist, if this information is simply not available in the returned object, or if I did not find the correct method to receive it.

asked 25 Apr '17, 15:07

autumnus's gravatar image

autumnus
1213311
accept rate: 0%


One Answer:

2

OpenStreetMap objects don't have a "class" and "type". Rather, they can have any number of tags and values. Nominatim simplifies that into a "class" and "type" - for example, something tagged building=house will boil down to class=building, type=house in Nominatim. Nominatim tries to guess what the "important" thing is about the object but if something is tagged amenity=place_of_worship and shop=books at the same time, Nominatim will have to choose and neither choice is "clearly correct". Overpass doesn't do this; it returns the full list of tags and their values, just as Osmium does. Osmium exposes the tags through the "tags" and "get_value_by_key" methods on the Object class, see: https://github.com/osmcode/libosmium/blob/master/include/osmium/osm/object.hpp#L324-L337

answered 25 Apr '17, 22:11

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

edited 26 Apr '17, 08:49

scai's gravatar image

scai ♦
33.3k21309459

I new about the functions "tags()" and "get_value_by_key()" and I recognized that Nominatim sometimes has two lines in its database with the same osm_id and different class and type. The fact, that the class and type are somehow "calculated" is new to me. That helps a lot and saves me time, as I don't have to search any more :-) Thanks!

(26 Apr '17, 12:54) autumnus

Source code available on GitHub .