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

Placeholder item in overpass API

0

Say I have a simple query that may or may not give a result. (and only one result, say with out 1) It runs fast, so I bundle them together into a single query. But the problem is that sometimes it will not return a result, so is there a simple solution to this? It would be easy if I there was a placeholder item in OSM, like this:

query goes here
way(0);

So that when processing the output, you could detect the placeholder.

Is there any nice way to do this?

asked 23 Sep '15, 19:34

CrazyDave2345's gravatar image

CrazyDave2345
55447
accept rate: 0%


One Answer:

2

First of all, a quick and dirty approach similar to your post.

node(1);out ids;

This will add a one liner to your query result, regardless of whether there was some result or not.

  <node id="1"/>

It shouldn't add too much overhead, after all.

There's one potential issue with that approach, though: if some mapper happens to delete that node #1, your marker is gone and you'll have to find some other available node. Of course, your normal query result also shouldn't produce a result, which looks like the marker, otherwise you cannot tell the both of them apart any longer.

The recommended approach involves the use of out count;. In the following example, we will first print all the buildings in the current bbox, followed by a total count:

[bbox:{{bbox}}];
way[building];
out geom;
out count;

Assuming there are no buildings in your bbox, you will still get the following summary information:

  <count total="0" nodes="0" ways="0" relations="0" areas="0"/>

answered 23 Sep '15, 19:56

mmd's gravatar image

mmd
5.7k15388
accept rate: 37%

edited 23 Sep '15, 20:09

Number two worked for me, thanks!

(23 Sep '15, 20:16) CrazyDave2345

Source code available on GitHub .