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

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

accept rate: 0%

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:

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"/>
permanent link

answered 23 Sep '15, 19:56

mmd's gravatar image

accept rate: 37%

edited 23 Sep '15, 20:09

Number two worked for me, thanks!

(23 Sep '15, 20:16) CrazyDave2345
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 23 Sep '15, 19:34

question was seen: 2,059 times

last updated: 23 Sep '15, 20:16

powered by OSQA