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

Hello guys,

I have UNION query

area["name"="London"]["admin_level"="6"];
node(area)["amenity"="cafe"]->.cafe;
node(area)["amenity"="bar"]->.bar;
(
.cafe;
.bar;
)->.all;
( .all; - ._; );
(._;);
out;

all is working good

BUT is there a way to grouping the received Nodes(or ways) like this?

<cafe>
  <node id="20849687" lat="51.4111705" lon="-0.3339165">
    <tag k="amenity" v="cafe"/>
    <tag k="note" v="is a trailer parked there, serving tea, sandwiches, ice-cream etc."/>
    <tag k="operator" v="ECSI Limited"/>
  </node>
  <node id="25475389" lat="51.5265807" lon="-0.1292505">
    <tag k="amenity" v="cafe"/>
    <tag k="fixme" v="not on FHRS"/>
    <tag k="name" v="Woburn Cafe"/>
  </node>
  ...etc (all cafes)
</cafe>
<bar>
  <node id="21593237" lat="51.5173465" lon="-0.1189566">
    <tag k="amenity" v="bar"/>
    <tag k="cuisine" v="polish"/>
    <tag k="food" v="yes"/>
    <tag k="name" v="Bar Polski"/>
    <tag k="toilets" v="yes"/>
    <tag k="toilets:access" v="customers"/>
  </node>
  ...etc (all bars)
</bar>

asked 01 Feb '18, 16:21

davittorosyan's gravatar image

davittorosyan
51448
accept rate: 0%

edited 01 Feb '18, 19:38


To group the results, get rid of the union and repeat the out statement (untested):

area["name"="London"]["admin_level"="6"]->.searchArea;
node(area.searchArea)["amenity"="cafe"];
out;
node(area.searchArea)["amenity"="bar"];
out;

They won't be grouped under cafe and bar elements in the output but they will be separated by type.

permanent link

answered 01 Feb '18, 21:20

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

edited 04 Feb '18, 00:31

Sorry, but don't works, only show the "Cafe" results. is there a way for example add some separator between categories? For example -------, or +++++ ?

(02 Feb '18, 06:01) davittorosyan

Sorry, the bar query didn't have any areas to search in. I've amended the query to save the search area to a set.

(04 Feb '18, 00:30) maxerickson

Sorry, but AFAIK, it is not possible as maxerickson already indicated. You try to introduce a tags that does not exist in the OSM model (bar & cafe).

You have to be aware that Overpass is just a very thin layer above the raw OSM data. Although it's powerful, you are still expected to write some code to format the result in the model you want.

permanent link

answered 02 Feb '18, 10:25

escada's gravatar image

escada
19.0k16166302
accept rate: 21%

amenity=cafe and amenity=bar are widely used tags, so I'm not sure what you mean here.

(02 Feb '18, 16:28) alester

@alester I mean can we somehow separate the results with some custom separators?

(02 Feb '18, 16:49) davittorosyan

They are widely used as value for v (see XML above), not as tag e. g. <pub>. The OP tries to create a whole new XML format. This is not possible server side and should be done locally

(02 Feb '18, 17:39) escada

Thank you guys for answers, but lets think from another angle of view

What if we will have one querie for pub and bars and between this 2 results insert additional line(for example "+++" this line)? Or this is also mran structure changing? My problem im 2 words - have 1 query but separate results in response.

Response I need, should be like this:

Pubs
+++
Bars
+++
Restaurants
+++
Fast foods
+++
Ets...
permanent link

answered 04 Feb '18, 15:04

davittorosyan's gravatar image

davittorosyan
51448
accept rate: 0%

edited 04 Feb '18, 15:10

1

You can use the make statement to insert elements between the out statements.

https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#The_make_statement

(05 Feb '18, 00:31) maxerickson

@maxerickson wow...thanks a lot finally i can see something, which can help resolve my problem. Can you see my comment below please.

(05 Feb '18, 13:30) davittorosyan

Thanks @maxerickson for solution, if you can please help me here also: I Have this part of code, and this is works good, my custom tag inserted with separate OUT in end of whole XML:

area["name"="London"]["admin_level"="6"];
node(area)["amenity"="cafe"]->.cafe;
node(area)["amenity"="bar"]->.bar;


(

.cafe;
.bar;

)->.all;


( .all; - ._; );

(._;);


out;

make my_element_name                           
     ::id = 1234,                            
     "tag1" = "this is the value of tag1",    
     "tag2" = 4711,                          
     "tag3" = date("2018-07-01");             
out;

is there solution to insert many custom tags after each category, for eaxmple?:

Cafes
<my_element_name1>
Bars
<my_element_name2>
etc...
permanent link

answered 05 Feb '18, 14:06

davittorosyan's gravatar image

davittorosyan
51448
accept rate: 0%

edited 05 Feb '18, 14:07

1

Simply place multiple make statements in the script.

(06 Feb '18, 00:36) maxerickson

sorry if my question will sounds simple...but i'm not expert on overpass queries.. but in my concept of query i wrote above in this comment, how can i place multiple "make"? this is union query and I cant imagine how i can insert between categories my "make"-s. can you please wrote example?

(06 Feb '18, 06:18) davittorosyan

UPDATE. @maxerickson I have some progress, please see comment below.

(06 Feb '18, 07:11) davittorosyan

I have some progress... current query

area["name"="London"]["admin_level"="6"];
node(area)["amenity"="cafe"]->.cafe;
node(area)["amenity"="bar"]->.bar;

make node                           
     ::id = 1,                            
     "tag1" = "aaa",    
     "tag2" = 4711,                          
     "tag3" = date("2018-07-01")->.my_custom_node1;

make node                           
     ::id = 2,                            
     "tag1" = "bbb",    
     "tag2" = 4711,                          
     "tag3" = date("2018-07-01")->.my_custom_node2;

(

  .cafe;
  .my_custom_node1;
  .bar;
  .my_custom_node2;

)->.all;


( .all; - ._; );

(._;);


out;

ONLY one problem i have now - ORDERING. I Know, Overpass by default return ordered by id, but is there a way, get response with this ordering ?

<cafe>(all cafes)
<my_custom_node1>
<bar>(all bars)
<my_custom_node2>

because currently this 2 custom tags added in very bottom of the whole result.

permanent link

answered 06 Feb '18, 07:16

davittorosyan's gravatar image

davittorosyan
51448
accept rate: 0%

edited 06 Feb '18, 07:16

1

You need to use multiple out statements, like in my earlier answer.

Note that ( .all; - ._; ); and (._;); aren't doing much in your script. The statement ending in ->.all leaves the default set (._) empty and those statements say "Subtract an empty set from my results and store it in ._" and "take the current default set and store it in the default set". Eliminating those two statements and using .all out; is a more direct way of doing the same thing.

Anyway, to get results all together with ordering determined by the server, use a union. To get results in an order that you determine, use multiple out statements.

(06 Feb '18, 12:51) maxerickson

@maxerickson you are one of the best Overpass QL masters. Thanks a lot for finding solution for this problem. Works fine for me, Thanks again

(06 Feb '18, 14:47) davittorosyan

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
×228
×85
×65

question asked: 01 Feb '18, 16:21

question was seen: 6,123 times

last updated: 06 Feb '18, 14:47

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