Sequence of the nodes (node id's) of lines

I’d like to know the sequence of the nodes of the line and I need a little help.
For example there is a line with id=412636792 (Way: ‪AB OMV Austria Exploration & Production‬ (‪412636792‬) | OpenStreetMap)
and it has 21 nodes with the following id’s:
324300340; 324300344; 4140119176; 328858625; 4140119177; 324300347; 4140119178; 1709516280; 4140119179; 339706231; 4140119180; 1560583323; 4140119181; 339706232; 4140119182; 1709516281; 6043439544; 1560583341; 4140119183; 1560583346; 339706235.

How can I know which is the first/last node and which is the next, …? so I’d like to know the sequence of the node id’s.

Thanks in advance.

1 Like

Fortunately, keeps nodes in their order anyway, so your list is already correctly ordered (starting with #324300340 and ending at #339706235).

Unless I’m missing something, there’s no extra processing you need to do to get the correct order of nodes.

1 Like

Thank you. Does it mean, that when a new node inserted into an existing line (i.e. because something changed in the line), then OSM can handle this situtation?

So, in case of attached situation will be the result of the query of the nodes the following?

324300340; 324300344; 4140119176; 328858625; 4140119177; 324300347; 4140119178; 1709516280; 4140119179; 339706231; 4140119180; 1560583323; 4140119181; 339706232; 4140119182; 1709516281; [id of inserted new node]; 6043439544; 1560583341; 4140119183; 1560583346; 339706235.

Best regards,


I don’t the answer to your question, but if you open the line in JOSM it’s easy to see what id’s nodes have by clicking on them.

1 Like

Yes, exactly the way as you described in your example.

1 Like

Thank you.

Thank you. But as I guess in this case there is an internal (hidden) id in the OSM database, which determine the sequence…

No, the way object is described as an array of nodes with the ID as the value.


As an example, this is what a node added to a way looks like in the *.osm file format that JOSM uses for locally saved edits. JOSM uses a negative id / ref number for new nodes that haven’t been uploaded yet.

<node id='-138605' action='modify' lat='53.48353611317' lon='-2.33880847827' />
<way id='1159196555' action='modify' timestamp='2023-04-02T16:01:51Z' uid='89098' user='InsertUser' version='1' changeset='134420557'>
    <nd ref='10779934280' />
    <nd ref='10779934279' />
    <nd ref='10779934269' />
    <nd ref='10779934278' />
    <nd ref='-138605' />
    <nd ref='10779934277' />
    <nd ref='10779934271' />
    <nd ref='10779934276' />
    <nd ref='10779934275' />
    <nd ref='10779934274' />
    <nd ref='10779934273' />
    <tag k='highway' v='service' />
    <tag k='service' v='parking_aisle' />

I suspect the aspect the OP is missing is that we always list all way nodes in the new* order when updating a way via the API.

* this is true even if we are only modifying tags, except that in that case it is just a restatement of the existing data.


Hallo Simon,
Probably, but what you mean OP?


Original Poster aka you :grinning:

1 Like

Hallo Toni,
it means, that the way object stored as array, so in this case the “hidden” ID I mentioned earlier is the array element id, isn’t?

Yeah, the index in the array represents the position in the sequence.

1 Like

Thank you :slightly_smiling_face:, and yes.

What I don’t get is that if I download the ways and nodes and try to build up the line (sequence of nodes) logically in my application, how can I know the order of the sequence (order) of the nodes.
If it is the situation, I have to record the nodes order (by creating an own order id) for the use later.


If you download using Overpass or the API, you’ll get XML data:

  <way id="769513663">
    <nd ref="2233422872"/>
    <nd ref="2233422879"/>
    <nd ref="2233422889"/>
    <nd ref="2233422897"/>
    <nd ref="3389568592"/>
    <tag k="highway" v="residential"/>

The sequence of the nodes is given by their appearance in the way description.


Thank you, so when a new node is inserted in a way, then the nodes are moved by one?

An example for the way (id=412636792):
“way nodes” as array:

*… *


after a new node inserted between 1709516281 and 6043439544 (see picture):

*… *
nodes[16]=new node id




1 Like

Correct, that’s what you get with a second download after uploading the changes (in JOSM, …).

The “new node id” is determined by the OSM DB-SW, not by you though. That’s why JOSM chooses a negative number as internal value.

Q: what does JOSM actually upload then? The negative number or an empty value (in the XML)?

1 Like

I get it: my dilemma is that
a) should I create an own “node-order-index” or
b) can I download/get a “node-order-index” directly from OSM
during or after download using Overpass or the API?


I see. Thank you.