Export number of nodes for a specific date

Hello,

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;
);

Now, I thought about exporting this data for different years. I found the following article about filtering for time stamps.
https://wiki.openstreetmap.org/wiki/DE:Overpass_API/Beispielsammlung#Stand_der_OSM-Daten_zu_einem_Stichtag

Can anyone help me and tell me how to put this option in my existing code? So i can just switch the date and export data for different years.

Thank you!

This brings back the following error.
" Error : line 4: parse error: ‘!’, ‘~’, ‘=’, ‘!=’, or ‘]’ expected - ‘:’ found."

Maybe something needs to be written to add these two arguments. Unfortunately, I’m not used to OSM QL. Do you have any idea?

I’m also only guessing

maybe, last try,

...
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"];
...

I tested around, made it work with the following code:

...

[out:csv( "de:regionalschluessel", name, total, nodes, ways, relations )][date:"2020-12-31T23:59:59Z"][timeout:400];
...

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?

Well, I have some queries set with timeout:1800 searching for example for all Flixbus routes in Europe or USA

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;
);

I think, the date given in [...] can be prologued.

So extending the area[...] could help here to find what was in OSM-DB End of 2020 - not sure though

area["ref:nuts:3"~"^DE"][date:"2020-12-31T23:59:59Z"];

You can’t select data from different years (between start end end of a year) though, but only from a specified point/second in time