Why not ask your question on the new OpenStreetMap Community Forum?

I have read some posts on this subject but none of them solved my problem.

I have a file Olszon.osm which opens well in JOSM, has one long way of about 7000 nodes. It starts with

<osm version="0.6" generator="osmfilter 1.2S"> <node id="137350351" lat="53.0048676" lon="106.9679891" version="8" timestamp="2013-01-23T00:04:12Z" changeset="14752406" uid="214969" user="AndrewBuck"/> <node id="137350353" lat="53.0111087" lon="106.9858454" version="8" timestamp="2013-01-23T00:04:12Z" changeset="14752406" uid="214969" user="AndrewBuck"/> ....

then in the middle start references:

<nd ref="2125463617"/> <nd ref="2125463613"/> <nd ref="2125463612"/> <nd ref="2125463611"/> ...

I tried to convert it to .csv file by typing:

osmconvert Olszon.osm --all-to-nodes --csv="@id @lat @lon" --csv=headline > Olszon.csv

but wat I get is Olszon.csv file that contains nodes but they are not in good order. The first node in .csv file has id = 137350351 but the first node on the way should have id = 2125463613.

How to solve the problem? Writing a script in VBA?

asked 30 May '14, 21:26

miko679's gravatar image

accept rate: 0%

Converting an OSM file to CSV is a task that can be done in different ways; however, since OSM files can normally contain multiple ways that sometimes share the same nodes, it is not generally possible to convert OSM to CSV so that "nodes are in the right order" - there might be any number of "right orders", even though in your specific case there's only one.

Writing a small program that does the conversion you want will probably be the easiest way - on Unix with Perl installed, this could be as simple as

perl -n -e 'if (/<node id=.(\d+).*lat=.([-0-9.]+).*lon=.([-0-9.]+)/) { $p{$1}=[$2,$3]; } elsif (/nd ref=.(\d+)/) { printf "%f,%f\n", $p{$1}[0],$p{$1}[1] }' < Olszon.osm
permanent link

answered 30 May '14, 22:10

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

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



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:


question asked: 30 May '14, 21:26

question was seen: 6,425 times

last updated: 30 May '14, 22:10

powered by OSQA