Count amenities per NUTS in multiple countries

I am new to overpass turbo and would like to count the number of amenities (pubs) per NUTS-3 (admin_level = “6”) for Germany and some other European countries.

I tried it the following code, which I saw in the example page:


[out:csv( "de:regiopubs", name, total, nodes, ways, relations )];


area["ISO3166-1:alpha3"="DEU"][admin_level="6"];

foreach->.regio(
  ( node(area.regio)[amenity=pubs];
    way(area.regio)[amenity=pubs];
    rel(area.regio)[amenity=pubs];);

  make count "de:regiopubs" = regio.set(t[ "de:regiopubs"]),
             name = regio.set(t["name"]),
             total = count(nodes) + count(ways) + count(relations),
             nodes = count(nodes),
             ways = count(ways),
             relations = count(relations);
  out;
);

Now I face to problems:
1.) If I execute the code the resulting csv is empty. I belive this is because of the wrong specification of area and its link to regio which seems to have a specific syntax-meaning (which I am unfortunately not aware of). Does anyone know how to fix this?

2.) Even though I could be able to draw all counts on admin_level = “6” for Germany at some point, to repeat it - say for other European countries - I would have to run it manually over every country. Is there a way to automate it for several countries but at the same admin_level?

Thank you very much in advance! :slight_smile:

You have written:

amenity=pubs

but with

amenity=pub

you will get much more results.

Hi, thank you for your immediate reply! Unfortunately, the result is the same:
https://ibb.co/R7fT1zz

I’m not sure I understand “ISO3166-1:alpha3”=“DEU”. The admin_level=“6” parts makes sense to me, as it is a key/value pair you would expect to find in the administrative units you are looking for, e.g. “https://www.openstreetmap.org/relation/62385”. But there isn’t a key called ISO3166-1:alpha3. Have you seen this working in another example? (I am not very familiar with Overpass myself so this might just be my own lack of knowledge).

More generally, you seem to have made several changes relative to the example, which I assume you took from “Count Pharmacies per County” here https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_API_by_Example. Have you tried making the changes one at a time to identify where things go wrong? E.g. start by simply replacing pharmacy with pub, and so on.

I don’t think regio is part of the language syntax, it is just the name given to the element you are looping over. So long as it is consistent in each place it occurs, I don’t think it should be a problem.

Hi alan_gr,

thank you very much for your reply and the input. Yes, indeed, I saw “ISO3166-1:alpha3”=“DEU” in another example. It is equal to “ISO3166-1”=“DE”, just referring to the UN alpha3 code of Germany instead of the alpha 2 “DE”. I put some time in understanding the pharmacy example a little bit better ( as you correctly pointed out) and it seems that de:regionalschluessel is a valid key in openstreetmap https://wiki.openstreetmap.org/wiki/DE:Key:de:regionalschluessel, referring to German district level. Thus it seems that this is a crucial element. I was able to change the code, and it runs, for other districts e.g. also

[out:csv( "de:regionalschluessel", name, total )];

area["de:regionalschluessel"~"^01.*"];

foreach->.regio(
  ( node(area.regio)[amenity=pharmacy];
  );
  
  make count "de:regionalschluessel" = regio.set(t[ "de:regionalschluessel"]),
             name = regio.set(t["name"]),
             total = count(nodes);
  out;
);

Yet, I am still unable to change the count level from this "“de:regionalschluessel” to some “admin_level”. Does anyone know how to get that change done?

Hi, it seems to work - at least partly - with the following code:

[out:csv( "count:byregion", name, total, nodes, ways, relations )];

area[boundary=administrative][admin_level=6]["de:regionalschluessel"];


foreach->.regio(
  node(area.regio)[amenity=pharmacy];
  make count "count:byregion" = regio.set(t[ "count:byregion"]),
             name = regio.set(t["name"]),
             total = count(nodes);
  out;
);

However, unforunately, the list of “Landkreise” is not complete, only reporting about 80 of over 400 available ones. :frowning: