NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


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

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×483
×3

question asked: 23 Sep '15, 19:34

question was seen: 2,980 times

last updated: 23 Sep '15, 20:16

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum