5

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?

4

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.

  • So there can be more than one out statement! Excellent, that helps a lot. One query to the API, one time load on the system but the full detail I need in return. – Ralf May 11 '15 at 12:12
  • 4
    If you find separate node and nd elements confusing, you might want to try the following alternative: way(35565161); out geom; – mmd May 13 '15 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.