NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

The are a few tools, which ingest OSM ways ids, but there is no tool to get them from a ".osm" file.

Is there any tool (pyosmium?) to print all ways ids from a osm file containing ways, nodes and relations?

asked 09 Mar '18, 08:55

landuse's gravatar image

landuse
1165511
accept rate: 0%

edited 09 Mar '18, 21:31

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

1

A command-line tool such as "grep" will get you a list - is that what you want? What OS are you running?

(09 Mar '18, 09:12) SomeoneElse ♦

Linux of course

(09 Mar '18, 09:30) landuse
2

grep "<way" my-osm-file.osm | cut -d\" -f2

(09 Mar '18, 10:13) Frederik Ramm ♦

Processing XML with the usual unix text processing tools always feels like doing things wrong, but then again, I'm not aware of a tool that does it better in a "pure XML" way. Is there one? There ought to be some sort of grep-like tool that takes XPath expressions...

(09 Mar '18, 16:54) turepalsson

The problem with actually trying to parse the XML is that you potentially have to load a very large amount of data to do so. There are XML processors around, but trying to do it that way will be much slower and more complicated that the way described above.

If on the other hand you wanted a list of "ways with a certain tag", then the answer might be different.

(09 Mar '18, 16:58) SomeoneElse ♦

If the file is not too big you can use xmlstarlet:

xmlstarlet sel -t -m /osm/way -v @id -n /path/file

The problem with this program is that it uses lots of RAM and with the usual OpenStreetMap osm files it easily fills up the RAM of an average desktop PC without even producing any output.

Otherwise there is osmium, a command tool which can print IDs on the standard output; then you have to filter what you need with awk/sed:

osmium cat -f opl /path/file | awk '/^w/{print substr($1,2)}'
permanent link

answered 12 Mar '18, 14:49

MarcoR's gravatar image

MarcoR
6873820
accept rate: 23%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×68
×55
×30
×1

question asked: 09 Mar '18, 08:55

question was seen: 2,354 times

last updated: 12 Mar '18, 14:49

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum