Overpass-API icon indicating copy to clipboard operation
Overpass-API copied to clipboard

Global bounding box does not apply to all statements

Open bjohas opened this issue 7 years ago • 4 comments

Maybe I'm misunderstanding the global bounding box - or maybe this is a bug?

This query produces all stops irrespective of bounding box http://overpass-turbo.eu/s/oYO :

[bbox:{{bbox}}]
[out:json][timeout:25];
{{sel=["network"~"London Underground"]["type"~"route"]["name"="Central"]}}
(
  relation{{sel}};
)->.a;
node(r.a:"stop");
out meta qt;

This one only produces stops in the bounding box http://overpass-turbo.eu/s/oYN :

[bbox:{{bbox}}]
[out:json][timeout:25];
{{sel=["network"~"London Underground"]["type"~"route"]["name"="Central"]}}
(
  relation{{sel}};
)->.a;
node(r.a:"stop")({{bbox}});
out meta qt;

I was expecting them both to be the same.

bjohas avatar May 12 '17 09:05 bjohas

XML equivalent for node(r.a:"stop")({{bbox}}):

<osm-script output="json" output-config="" timeout="250">
  <query into="a" type="relation">
    <has-kv k="network" modv="" regv="London Underground"/>
    <has-kv k="type" modv="" regv="route"/>
    <has-kv k="name" modv="" v="Central"/>
  </query>
  <query into="_" type="node">
    <bbox-query e="-0.09209632873535156" into="_" n="51.52970522368333" s="51.50529669917622" w="-0.14037609100341797"/>
    <recurse from="a" into="_" role="stop" role-restricted="yes" type="relation-node"/>
  </query>
  <print e="" from="_" geometry="skeleton" limit="" mode="meta" n="" order="quadtile" s="" w=""/>
</osm-script>

Global bounding box XML equivalent:

<osm-script bbox="51.50529669917622,-0.14037609100341797,51.52970522368333,-0.09209632873535156" output="json" output-config="" timeout="250">
  <query into="a" type="relation">
    <has-kv k="network" modv="" regv="London Underground"/>
    <has-kv k="type" modv="" regv="route"/>
    <has-kv k="name" modv="" v="Central"/>
  </query>
  <recurse from="a" into="_" role="stop" role-restricted="yes" type="relation-node"/>
  <print e="" from="_" geometry="skeleton" limit="" mode="meta" n="" order="quadtile" s="" w=""/>
</osm-script>

QL parser could generate an item query with a recursion instead, so that the global bounding box is effective as a constraint. Otherwise, we're processing this part via Recurse_Statement::execute(Resource_Manager& rman), which does not honor the global bounding box.

<osm-script bbox="51.50529669917622,-0.14037609100341797,51.52970522368333,-0.09209632873535156" output="json" output-config="" timeout="250">

  <query into="a" type="relation">
    <has-kv k="network" modv="" regv="London Underground"/>
    <has-kv k="type" modv="" regv="route"/>
    <has-kv k="name" modv="" v="Central"/>
  </query>
  <query into="_" type="node">
    <recurse from="a" into="_" role="stop" role-restricted="yes" type="relation-node"/>
  </query>
  <print e="" from="_" geometry="skeleton" limit="" mode="meta" n="" order="quadtile" s="" w=""/>
</osm-script>

mmd-osm avatar Aug 13 '17 20:08 mmd-osm

How about adding || parsed_query.get_global_bbox_limitation().valid() to map_ql_parser.cc:1495 There's some issue with Statement_Dump, though, which doesn't have an idea about this global_bbox_limitation (that's another unrelated bug in the current coding).

   || (clauses.front().statement == "newer" && type != "all")
   || (clauses.front().statement == "recurse" &&
       (clauses.front().attributes[0] == "<" || clauses.front().attributes[0] == "<<"
       || clauses.front().attributes[0] == ">" || clauses.front().attributes[0] == ">>"
        || parsed_query.get_global_bbox_limitation().valid()  )))
{
  statement = create_query_statement< TStatement >
      (stmt_factory, type, into, query_line_col.first);

mmd-osm avatar Aug 13 '17 21:08 mmd-osm

Short notice: it is intended that the recurse statement does not use the global bounding box: I expect that consumers more often need all members of a way than are harmed by some extra data.

However, there is probably need for adjustments, for better documentation, or both. Hence, the bug label.

drolbr avatar Aug 24 '17 16:08 drolbr

BTW: Recurse doesn't really need a global bbox here, an additional filter could restrict the result accordingly:

[bbox:{{bbox}}]
[date:"2017-05-12T00:00:00Z"]
[out:json][timeout:25];
{{sel=["network"~"London Underground"]["type"~"route"]["name"="Central"]}}
(
  relation{{sel}};
)->.a;
node(r.a:"stop");
node._;                   // additional filtering according to global bbox
out meta qt;

mmd-osm avatar Dec 05 '17 21:12 mmd-osm