Search code examples
overpass-api

How can I find all nodes around a point that are members of a way with a certain tag?


I would like to find all highway way member nodes in a certain radius. I cannot see how to do this without using intersection, however, that is not in the API. For example I have this:

[out:json];
way(around:25, 50.61193,-4.68711)["highway"];>->.a; 
(node(around:25, 50.61193,-4.68711) - .a);
out;

Result set .a contains the nodes I want but also nodes outside the radius - potentially a large number if the ways are long. I can find all the nodes inside the radius I don't need, as returned by the complete query above. Now I can always perform a second around query and do the intersection of the two result sets outside of Overpass. Or I can do another difference:

[out:json];
way(around:25, 50.61193,-4.68711)["highway"];>->.a; 
(node(around:25, 50.61193,-4.68711) - .a)->.b;
(node(around:25, 50.61193,-4.68711) - .b);
out;

This gives the result I want but can it be simplified? I'm certain I'm missing something here.


Solution

  • Indeed, your query can be simplified to an extent that we don't need any difference operator at all. I would recommend the following approach:

    • We first query for all nodes around a certain lat/lon position and a given radius.
    • Based on this set of nodes we determine all ways, which contain some of the previously found nodes (-> Hint: that's why we don't need any kind of intersection or difference!).
    • Using our set of highway ways we now look again for all nodes of those ways within a certain radius of our lat/lon position.

    In Overpass QL this reads like:

    [out:json];
    node(around:25, 50.61193,-4.68711);
    way(bn)[highway];
    node(w)(around:25, 50.61193,-4.68711);
    out;
    

    Try it on Overpass Turbo