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