[GIS] Correct order of nodes in Overpass query

openstreetmapoverpass-api

I am struggling to get the correct order of nodes out of an Overpass query.

I am aware of this similar question How do you get the nodes of an area in Overpass API in the "right" order? but I am not sure if I understand the solution hinted there. I wish the text was a bit more explicit how this is solved in the end.

Let's for example use way ID 35565161:
http://www.openstreetmap.org/way/35565161#map=15/49.3949/4.0426
http://api.openstreetmap.org/api/0.6/way/35565161

What I found is that running my query "api/interpreter?data=way(35565161);>;out body;" does not return the nodes in the correct order.

I think I understand the answer to the question linked above that I have to first run a query on the way to get the order of nodes, then run another query on the node details to get the node coordinates.

With those two available iterate over the way, referencing the detail results from the second.

That seems a bit too much work – I guess there is an easier way to do this in one query?

Best Answer

Nodes don't have any order themselves. Keep in mind that a single node can be part of multiple ways. Therefore each node can have a different position for each way it belongs to. Hence you have to query for the way, too, to get the order of its nodes:

way(35565161);
out body;
>;
out body;

or

way(35565161);
(._;>;);
out body;

See the result on overpass turbo.

The order of <node>s inside the result is completely irrelevant. The relevant information is the order of <nd>s inside the <way> your are interested in. Each <nd> element will reference a specific node ID, the order of all <nd> elements represent the order of nodes for this particular way.