Use Overpass API to output different tag counts as CSV

I want to create CSV data with different OpenStreetMap tag counts for selected cities using Overpass API. Unfortunately, the “Counting Objects” section of the Overpass API Documentation is still empty. Also, this count function documentation only shows how to count nodes, ways, relations or a combination for a single tag query.

How can an output containing several columns for different tag counts be achieved?

I found this helpful example for counting pharmacies.

And this is what my query currently looks like:

// Define fields for CSV output
[out:csv(name, "node[railway=station]", "node[highway=bus_stop]")];

// Select area
{{geocodeArea:München}}->.munich;

// Query stations and bus stops
node(area.munich)[railway=station];
//node(area.regio)[highway=bus_stop]; // How can this count be added separately?

// Count stations
make count name = munich.set(t["name"]),
           "node[railway=station]" = count(nodes);

// Output CSV
out; 

If I uncomment the node(area.regio)[highway=bus_stop]… line, only the bus stop count is contained in the output, but should appear in an additional column next to the railway station count.

Please note: This question has originally been posted at GIS StackExchange.

L1,4. You shouldn’t have name= , as it is used in =pharmacy for the de:regionalschluessel= they are in . Not meaningful to have .set(t["name"]) here , other than making it very long. The format can be [out:csv(feature, number)]; .
L3. They need to be put into different sets, as count( can only count a set. Can’t use union by bracketing them.
L4,5. Each make needs to be out; separately. That’s the simplest method.

 [out:csv(feature, number)];
{{geocodeArea:München}}->.munich;  
node(area.munich)[railway=station] -> .railstations;
node(area.munich)[highway=bus_stop] -> .busstops; 
make count feature = "railway=station",
           number = railstations.count(nodes);
out;
make count feature = "highway=bus_stop",
           number = busstops.count(nodes);
out; 

Fundamentally they can be totally separate, without using sets.

 [out:csv(feature, number)];
{{geocodeArea:München}}->.munich;  
node(area.munich)[railway=station]; 
make count feature = "railway=station",
           number = count(nodes);
out;
node(area.munich)[highway=bus_stop];
make count feature = "highway=bus_stop",
           number = count(nodes);
out; 
2 Likes