1

Does Overpass (or Overpass Turbo) provide a mechanism for query like “show me the number of nodes tagged foo=bar by country”?

Output being something like this:

Country    Count
Estonia    5
Latvia     8
Lithuania  6
Poland     42683
Czechia    2653
Germany    1458

Doesn’t have to be nicely formatted, CSV would be fully sufficient.

Is that possible in Overpass? If so, how?

1

1 Answer 1

1

In principle, yes, it is possible:

// Define fields for csv output
[out:csv(name, total)][timeout:2500];

//All countries
area["admin_level"=2];

// Count in each area
foreach->.regio(
  // Collect all Nodes with highway=milestone in the current area
  ( node(area.regio)[amenity=pharmacy];
    way(area.regio)[amenity=pharmacy];
    rel(area.regio)[amenity=pharmacy];);

  // assemble the output
  make count name = regio.set(t["name:en"]),
             total = count(nodes) + count(ways) + count(relations);
  out;
);

Adapt to your needs by:

  • Dropping node, way or area if you are not interested in that object type
  • Altering the set of tags for the objects to count
  • Adding more tags of the country as fields
  • Adding per-type counts as fields

In practice, however, these queries get huge and can quickly time out, giving you only partial results. If you are only interested in a certain area, you can try constraining the list of countries to iterate over by e.g. specifying additional attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.