With some help I created the following script to export the number of gas stations per NUTS 3 region in Germany.
[out:csv( "de:regionalschluessel", name, total, nodes, ways, relations )];
//All NUTS 3 regions in Germany
area["ref:nuts:3"~"^DE"];
// Count the fuel stations in each area
foreach->.regio(
// Collect all Nodes, Ways and Relations wth amenity=fuel in the current area
( node(area.regio)[amenity=fuel];
way(area.regio)[amenity=fuel];
rel(area.regio)[amenity=fuel];);
make count "de:regionalschluessel" = regio.set(t[ "de:regionalschluessel"]),
name = regio.set(t["name"]),
total = count(nodes) + count(ways) + count(relations),
nodes = count(nodes),
ways = count(ways),
relations = count(relations);
out;
);
...
foreach->.regio(
// Collect all Nodes, Ways and Relations wth amenity=fuel in the current area
[date:"2020-12-31T23:59:59Z"];( node(area.regio)[amenity=fuel];
way(area.regio)[amenity=fuel];
rel(area.regio)[amenity=fuel];);
...
or is it
[out:csv( "de:regionalschluessel", name, total, nodes, ways, relations )];[date:"2020-12-31T23:59:59Z"];
//All NUTS 3 regions in Germany
area["ref:nuts:3"~"^DE"];
...
At least, I think it’s working, because it displays different number of nodes. But after the timeout of 400 seconds (I think) it only generated 32 out of 402 regions. Is it normal that a complex query takes that long? Do I just have to prolong the timeout until it works?
Could counting only the nodes instead of nodes ways and relations cut down the time?
If I only want to count the number of gas stations, this should be the nodes with amenity=fuel. Or are gas stations sometimes just marked as ways or relations?
I have a question and I can’t find an answer for hours now…
You helped me to select the regions with NUTS classifications before. But in the output CSV it displays the regional keys. Since the filter is for NUTS3 keys starting with “DE” there should be a way to export these keys as well right?
An example:
NUTS 3 key Stuttgart: DE111
regional key Stuttgart: 08111 or 081110000000
for other regions it is 09 in the beginning, so 08 doesn’t equal DE and also the last 3 digits differ for some regions.
The ones exported right now are the regional keys and don’t start with “DE”
[out:csv( "de:regionalschluessel", name, total, nodes, ways, relations )][date:"2020-12-31T23:59:59Z"][timeout:20];
//All NUTS 3 regions in Germany
area["ref:nuts:3"~"^DE"];
// Count the fuel stations in each area
foreach->.regio(
// Collect all Nodes, Ways and Relations wth amenity=fuel in the current area
( node(area.regio)[amenity=fuel];
way(area.regio)[amenity=fuel];
rel(area.regio)[amenity=fuel];);
make count "de:regionalschluessel" = regio.set(t[ "de:regionalschluessel"]),
name = regio.set(t["name"]),
total = count(nodes) + count(ways) + count(relations),
nodes = count(nodes),
ways = count(ways),
relations = count(relations);
out;
);