April 11, 2023, 7:12am
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.
osm.org 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.
April 11, 2023, 8:53am
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; 1560583341; 4140119183; 1560583346; 339706235. [id of inserted new node]; 6043439544;
April 11, 2023, 10:08am
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.
April 11, 2023, 11:29am
Yes, exactly the way as you described in your example.
April 11, 2023, 11:36am
Thank you. But as I guess in this case there is an internal (hidden) id in the OSM database, which determine the sequence…
April 11, 2023, 11:41am
No, the way object is described as an array of nodes with the ID as the value.
April 11, 2023, 11:44am
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
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' />
April 11, 2023, 1:10pm
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.
April 11, 2023, 1:29pm
Probably, but what you mean OP?
April 11, 2023, 1:32pm
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?
April 11, 2023, 1:36pm
Yeah, the index in the array represents the position in the sequence.
April 11, 2023, 1:39pm
, 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.
April 11, 2023, 1:43pm
If you download using Overpass or the API, you’ll get XML data:
<tag k="highway" v="residential"/>
The sequence of the nodes is given by their appearance in the way description.
April 11, 2023, 1:53pm
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=new node id
April 11, 2023, 1:58pm
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)?
April 11, 2023, 1:58pm
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?