This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Strange query result with union in overpass

1
<query type="way">
<has-kv k="int_ref" v="E 40"/>
</query>
<union>
<query type ="node">
<bbox-query s="49.7688" n="50.1479" e="22.8337" w="21.9143"/>
<around radius="4500"/>
<has-kv k="place" v="town"/>
</query>
<query type ="node">
<bbox-query s="49.7688" n="50.1479" e="22.8337" w="21.9143"/>
<around radius="4500"/>
<has-kv k="place" v="city"/>
</query>
<query type ="node">
<bbox-query s="49.7688" n="50.1479" e="22.8337" w="21.9143"/>
<around radius="4500"/>
<has-kv k="place" v="village"/>
</query>
</union>
<print/>

The following query should return all the nodes with k value town, village or city withing the given bound box and no more further than 4500 from way referenced E 40. However in xml result there is no "city" values. When I cut out <union> with "town" and "village" query and search only for those with key value "city" then the result is ok . I wonder what is the reason. Regards

asked 02 Mar '15, 13:43

huberttt's gravatar image

huberttt
31224
accept rate: 0%

edited 02 Mar '15, 14:11

1

This is really odd. When I ran it as you have written above, I only received town results. If I eliminate town I receive some but not all city and village results.

<query type="way">
<has-kv k="int_ref" v="E 40"/>
</query>
<query type="node">
<bbox-query s="49.7688" n="50.1479" e="22.8337" w="21.9143"/>
<around radius="4500"/>
<has-kv k="place" regv="city|village|town"/>
</query>
<print/>

gives you a more inclusive set of results, but I am not sure if it is right or not.

(03 Mar '15, 00:23) baghaii

Yes, I have already managed to write same code myself. Thank you for your response anyway. I still just don't know where is the problem in my previous query

(03 Mar '15, 07:26) huberttt

One Answer:

5

The "around" block in each query is relative to the preceding statement. The query block for "town" looks around the "E40". The next query block looks around the results of the "town" query block and so on. One solution would be to use a variable instead, i.e.:

way[int_ref="E 40"]->.e40;
( node(49.768,21.914,50.148,22.834)(around.e40:4500)[place=town];
  node(49.768,21.914,50.148,22.834)(around.e40:4500)[place=city];
  node(49.768,21.914,50.148,22.834)(around.e40:4500)[place=village]; );
out;

This is the query you probably intended.

The other, and probably more efficient solution is the one from the comment of baghaii.

answered 03 Mar '15, 07:14

Roland%20Olbricht's gravatar image

Roland Olbricht
6.7k36489
accept rate: 36%

Source code available on GitHub .