Search notes:

Overpass API: foreach statement

Print population of cities in Croatia

[out:csv(
  ::id,
    name,
    population
)];

area[ 'ISO3166-1' = 'HR' ];

node[place=city](area);

foreach {

  make x
     ::id       = u(  id()         ),
     name       = u(t['name'      ]),
     population = u(t['population'])
  ;

  out;
}

Count number of amenity=drinking_water in each canton of Switzerland

[out:csv(
   iso_3166_2,
   name,
   total,
   nodes,
   ways,
   relations
)];

area['ISO3166-2' ~ '^CH-'];

foreach -> .kanton(

  nwr
     (area.kanton)
     [amenity = drinking_water];
  
  make count
     iso_3166_2             = kanton.set(t['ISO3166-2']),
     name                   = kanton.set(t['name'     ]),

     total                  = count(nodes) + count(ways) + count(relations),

     nodes                  = count(nodes    ),
     ways                   = count(ways     ),
     relations              = count(relations);

  out;
);
Almost the same thing, but with out count.

See also

The for statement.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758855985, '216.73.216.5', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/OpenStreetMap/API/Overpass/statements/foreach(92): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78