1

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?

1

You need a part of the answer for ways. Ways in OSM are ordered lists of node references.

So the part of the answer what you need should looks like:

<way id="22940464">
    <nd ref="272304964"/><!-- First node -->
    <nd ref="273206415"/><!-- Second node -->
    <nd ref="273206424"/>
    <nd ref="1827734835"/>
    <nd ref="272307378"/>
    <nd ref="3263545766"/>
    <nd ref="247110585"/><!-- Last node -->
    <tag k="highway" v="unclassified"/>
    <tag k="name" v="Via Maurizio Monti"/>
    <tag k="oneway" v="yes"/>
</way>

Where <nd ref="1827734835"/> refers to node 1827734835. And below details for that node with coordinates:

<node id="1827734835" lat="45.8122890" lon="9.0889686"/>

I've rewrited your query with OverpassQL:

[out:xml][timeout:25];

// filter ways
way[highway][highway!~"footway|cycleway|path|service|track"]({{bbox}})->.hw;

// foreach way
foreach.hw->.eachw(
  // get ways, which shares same nodes minus current way
  // into .otherws
  node(w.eachw)->.ns;
  way(bn.ns)[highway][highway!~"footway|cycleway|path|service|track"]->.w2;
  (way.w2; - way.eachw;)->.otherws;

  // get shared nodes
  node(w.otherws)->.n2;
  node(w.eachw)->.n3;
  (((node.n2; node.n3;) -(node.n2; - node.n3;);) -(node.n3; - node.n2;);)->.shrdnodes;

  // ways which are in junction
  way(bn.shrdnodes)->.outways;

  // union ways and nodes
  (way.outways; node.shrdnodes;); out;

  // dirty hack
  //(node(100000); node(w.outways); node(100000);); out;  
);

At this point, you'll get a shared points, and ways after them. You may send separate querys to get highways geometries, or uncomment a row after //dirty hack.

What those hack does and why we need it. Without it, you'll got:

  • junction nodes
  • junction ways, but without a nodes

the re is no option for overpass to get a list of set which object belongs to, or mark your result set in any other way.

So I use node(100000) (node with id=100000) as a bracket for my output to group nodes, which are not a shared nodes, but just a nodes to build full geometry of a way. If there be an option to include datasets to answer as a meta for objects, I could just add all nodes with different sets.

So the overpass answwer looks like

<!-- my shared nodes which I looking for -->
<node id="175040709" lat="56.8281187" lon="60.6118371"/>
<node id="175048158" lat="56.8278883" lon="60.6097093"/>
<node id="410047434" lat="56.8274783" lon="60.6059228"/>

<!--ways which are in junction -->
<way id="20107663">
    <nd ref="175040709"/>
    <nd ref="803415497"/>
    <!-- skip some xml here -->
  </way>
  <way id="34939324">
    <!-- skip some xml here -->
  </way>
  <way id="56640542">
    <!-- skip some xml here -->
  </way>
  <way id="118465904">
    <!-- skip some xml here -->
  </way>
  <way id="148027458">
    <!-- skip some xml here -->
  </way>

<!-- my bracket node -->
  <node id="100000" lat="58.4215584" lon="15.6183153"/>

<!-- nodes to build full geometry -->
  <node id="175040705" lat="56.8283647" lon="60.6140898">
    <tag k="highway" v="traffic_signals"/>
  </node>
  <node id="175040709" lat="56.8281187" lon="60.6118371"/>
  <node id="175048158" lat="56.8278883" lon="60.6097093"/>
  <node id="175048160" lat="56.8274040" lon="60.6052596"/>
  <node id="176277604" lat="56.8351416" lon="60.6094024">
  <!-- more nodes here -->

<!-- my bracket node again-->
  <node id="100000" lat="58.4215584" lon="15.6183153"/>

<!-- next portion of junction ways and nodes -->

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.