6

I'm learning how to build queries to use OverpassTurbo and retrieve data from OpenStreetMap.

Can anyone help me to understand this query?

(
  node["shop"="bicycle"]({{bbox}});
  way["shop"="bicycle"]({{bbox}});
  relation["shop"="bicycle"]({{bbox}});
);

out body;

>;

out skel qt;

I am confused by the need to query relations when looking for bike shops and by the meaning of this syntax:

();
out body;
>; 
out skel qt;
8

overpass turbo wizard uses a template based approach to create an Overpass QL query. This way you can easily get started with Overpass API without having to deal with all the details. For many use cases the wizard creates useful queries out of the box already.

Now, regarding your questions: by default, those queries include both nodes, ways and relations. To change this behavior and create a query for a certain type, you can use the type: syntax as outlined in the wiki. There are many other ways to control the query creation, just take a look at different options on said wiki page.

  • ( ) is a union block statement, which simply combines the result of the individual queries, in this case the set of all nodes, ways and relations with shop=bicycle in the current bbox. You can read more about it here

  • out body; : this prints all information necessary to use the data. These are also tags for all elements and the roles for relation members. see Print action. This first step will print all of the node details, the ways (without nodes(!)) and relations (without details about ways and nodes(!)) you requested.

  • >; : This statement is called recurse down and resolves ways to its nodes, and relations to its ways and nodes.

  • out skel qt; - in this last statement, we will now print out the results of the previous >; (recurse down) statement. To reduce the amount of unwanted by-catch, we use out skel instead of out body;. The idea here is to just return the geometry information, but leave out any tags. qt is a sorting option (by quadtile), which is also meant as a performance optimization.

To get a better understanding of those different statements, you could e.g. comment out out skel qt; run the query again and check the results in overpass turbo. Or try out meta; instead of out body; to also get meta data (version information, last changed date, etc.).

Depending on your changes, you might find an empty map and only some data in the "Data" tab in overpass turbo.

BTW: Instead of out body; >; out skel qt; you can also use out geom; when using overpass turbo. Note that the output format will not be 100% compatible with the normal OSM XML format in that case.

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.