Friday, 11 December 2015

openstreetmap - Correct order of nodes in Overpass query


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?




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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...