I am currently downloading all the street intersections from a bounding box using the query below (see it on overpass).
<query type="way" into="hw">
<has-kv k="highway"/>
<has-kv k="highway" modv="not" regv="footway|cycleway|path|service|track"/>
<bbox-query e="9.1775" n="45.8428" s="45.7581" w="8.9904"/>
</query>
<foreach from="hw" into="w">
<recurse from="w" type="way-node" into="ns"/>
<recurse from="ns" type="node-way" into="w2"/>
<query type="way" into="w2">
<item set="w2"/>
<has-kv k="highway"/>
<has-kv k="highway" modv="not" regv="footway|cycleway|path|service|track"/>
</query>
<difference into="wd">
<item set="w2"/>
<item set="w"/>
</difference>
<recurse from="wd" type="way-node" into="n2"/>
<recurse from="w" type="way-node" into="n3"/>
<query type="node">
<item set="n2"/>
<item set="n3"/>
</query>
<print/>
</foreach>
The output is a 92 pages doc (including duplicates) containing nodes(node id, lat and long). I am extracting the latitudes and longitudes in order to compose a Google Street View Image link because i want to download for each point the corresponding image. In the composition of the link I also want to calculate the heading-angle of the street;
I know the math formula needed but it requires 2 lat and 2 long (from 2 points in the same street) and my problem is that the nodes in the output file don't have a specific order. Therefore, i cannot calculate the angle between two consecutive nodes.
I was thinking of sorting the lat or long in asc/desc order because in this way i might find the points in the same street. Is this method valid or i can solve it in an easier way? Is there any more efficient way to find all the street intersections?