Search code examples
overpass-api

How to limit the search area with Overpass turbo when looking for intersections


I have a couple of intersections I would like to geocode. It works currently with the following query.

https://overpass-api.de/api/interpreter?data=[out:json];way[highway][name=%22Howard Avenue%22];node(w)-%3E.n1;way[highway][name=%22Dick Street%22];node(w)-%3E.n2;node.n1.n2;out;

However, for some of the intersections I am looking for I get results from different locations all over the world. Since I do have information about state and country I would like to include this in my search.

However, using the following query I do not get any result:

[out:json];
{{geocodeArea:New Jersey, USA}}->.searchArea;
(
  node["name"="Howard Avenue"](area.searchArea);
  node["name"="Dick Street"](area.searchArea);
) -> .allNodes;
node(w.allNodes)(w.allNodes);
out;

Also, when exporting the query I get the following:

[out:json];
area(3600224951)->.searchArea;
(
  node
    ["name"="Howard Avenue"]
    (area.searchArea);
  node
    ["name"="Dick Street"]
    (area.searchArea);
)->.allNodes;
node
  (w.allNodes)
  (w.allNodes);
out;

Where the search area is translated into some number.

Is there a way to get the query written so that I have a url like the one above, where the search area is clear text?


Solution

  • In the second example you have posted, you're looking for highway names on a node, whereas you would find these usually on ways. The very first example "https://overpass-api.de/api/interpret..." you have posted does it correctly. Since .allNodes is empty, the remainder of the query (which has further semantic issues) won't return any data.

    What you could do though is to add the (area.searchArea) filter to your working query:

    [out:json];
    
    {{geocodeArea:New Jersey, USA}}->.searchArea;
    
    way[highway][name="Howard Avenue"](area.searchArea);node(w)->.n1;
    way[highway][name="Dick Street"](area.searchArea);node(w)->.n2;
    
    node.n1.n2;
    out;