I am using the turbo overpass api to get all the elements in a small bounding box and export it to a shapefile.
Now, I would like to split the elements into layers where each layer is a category such as building, highway etc. My problem is that OSM categories are not mutually exclusive and something can be both building and amenity for example. I need to find the best solution where every element only gets exactly one category.
I understand there might not be an optimal solution since in OSM (and also in reality) things do not fall into distinct categories but I’m looking for the best next thing.
My current solution is to subjectively rate tags based on importance and use the most important one on the element.
Are there any common solutions out there? or a commonly used tag importance order?
It really depends on what your output model looks like. For example if an amenity can have a polygon as geometry (and not just a point), I would simply duplicate the geometry in your output.
There are other difficulties doing this, for example deciding which tags belong to which entity. Editors, for example iD, JOSM and Vespucci, match tags with presets to do this, but it is a necessarily imperfect process.
I suspect that there are almost as many as there are data consumers (or at least, types of data consumers). Here’s mine. In that file you’ll see a few examples of “if something is tagged as both an X and a Y, process it as an X”. The data that results from that:
Favours “historic” tags over other tags that might be set
Favours almost anything else over “tourist attraction”
Tries to “untag for the renderer” by detecting where people have tried to work around OSM Carto’s cartography and detect what something actually is instead
However this approach is just mine; other people will do things differently. You’ll have to ask yourself "if I see an X and a Y, which is more important to me? You can look at taginfo to look at tag combinations across the board rather than one by one.