I want to filter the OSM US file for all the roads, basically anything that has a highway tag. I understand roads can be either ways or relations, so I tried running the following query:
osmosis
–read-xml input.osm
–tf accept-ways highway=*
–tf accept-relations highway=*
–used-node
–write-xml output.osm
I then searched for the nearest_edges using osmnx.nearest_edges function from the osmnx library.
I used 1000 latitude,longitude points. However, when I compared the results of using the full OSM file vs this filtered OSM file, 32 road types were missing on the filtered graph.
Any ideas on how to modify my query? I want to get the road type as small as possible?
Maybe instead of filtering highway and nodes, I can drop all buildings or cafes. Anything to make sure I don’t lose all the roads, but simplify the graph as much as possible. Thank you.
The latest version of the osmium tool is v1.16; and it’s recommended to use this version.
If you are struggling with compiling the software packages, it’s advisable
to use conda-forge (available for linux-64, osx-64, win-64).
If you are focusing on the roads, in my opinion, it might also be worth filtering out the ferry routes ( route=ferry ). Tag:route=ferry - OpenStreetMap Wiki
But it’s also advisable to check visually because sometimes even that is not enough.
I’m slightly surprised that neither of the previous posts pointed this out, but there is no relation type that utilises the highway tag and is used for modelling roads. With other words the option is unnecessary.
Unfortunately the initial post suggested perhaps a bit of a deeper misunderstanding:
The highway tag is used for all sorts of things - areas, crossings, and lots more. Depending on what you want, you might also want to exclude a highway=footway like here.
I suspect that the relations that you might be interested are route relations like this one. In the US, a way such as this might be part of multiple route relations.
However, what you actually want in your resulting file rather depends on what you want to do with the data.
Yes, that approach can also work. You might also find osm-tags-transform useful for that.