Search notes:

Overpass API: functions

angle() Calculates angle between two segments in a way
center(…) Expects a function that returns a geometry and calculates center of the bounding box of its argument.
changeset() Returns the id of the changeset for last update to an object
count(…) Count the number of objects with a given type (nodes, ways etc.)
count_by_role() Count number of members with a specific role
count_distinct_members() Count number of distinct members
count_distinct_by_role() Count number of distinct members with a specific role
count_members() Count number of members for an object
count_tags() Count tags for an object
date(…) Turns its argument into a number representing a date, for comparison purposes only
gcat(…) Calculate combined geometry from its input set
geom() Returns geometry of an object
hull(…) Expects a function that returns a geometry and returns the convex hull of its argument.
id() Returns OSM id of an object
is_closed() Returns 1 if a way is closed (first and last node are the same), and 0 otherwise.
is_date(…) Tests whether its argument represents a date
is_number(…) Returns 1/0 depending on which its argument is a number
is_tag("name") Returns 1 if an object has a tag called name. Otherwise 0. Compare with t.
keys() Returns keys for a given object
lat(), lon() Latitude/longitude of an object (or its bounding box centroid)
length() Returns length of an object. Will be length of a way or all ways in a relation
lrs_in(…,...) Returns 1 if its first argument is contained in the set provided as a second argument
lrs_isect(…,...) Returns the intersection of its two arguments, treated as sets
lrs_min(…) Returns the minimum of the elements in its argument
lrs_max(…) Returns the maximum of the elements in its argument
lrs_union(…,...) Returns the union of its two arguments, treated as sets
lstr(..,..) Returns linestring constructed from its arguments
min(…) Returns minimum value in the set provided as a parameter
max(…) Returns maximum value in the set provided as a parameter
number(…) Convers argument to a number, or "NaN"
per_member(…) Executes its argument once per member of the element
per_vertex(…) Executes its argument once per vertex of the element
poly(…, …) Returns a polygon constructed from its arguments
pos() Position for a member within an element
pt(lat, lng) Returns a valid OSM node geometry for given location
set(…) Returns semicolon list of all distinct values in its input. Compare with u(…)
suffix(…) Returns any value following a number in its input
sum(…) Sums values in set provided as parameter
timestamp() Returns timestamp of an object
trace(…) Expects a function that returns a geomatry and returns the trace (whatever this is?) of its argument.kkkj
type() Returns type of an object. E.g. node or way.
t["name"] Returns value of the name tag. Compare with is_tag.
u(…) Returns the value of sets whose members contains unique values, compare with set(…).
uid() Returns user id of the user who last edited an object
user() Returns user name of last editor of an object
version() Returns version number of an object

is_tag

Find objects that have a complete 5-tuple of the addr: tags country, postcode, city, street and housenumber (Inspired by this Overpass API Issue).
{{geocodeArea:Stadtmitte, Düsseldorf}}->.searchArea;
  
nwr(area.searchArea)
  (
      if:(is_tag("addr:country"     ) +
          is_tag("addr:postcode"    ) +
          is_tag("addr:city"        ) +
          is_tag("addr:street"      ) +
          is_tag("addr:housenumber")) == 5
   );

out;

per_member

[out:csv(
   ids  ;
   false
)];

way(60538085);

for (per_member(ref())) {
   make x
     ids = _.val;

   out;
}

lon/lat

[out:json];

area[name='Pfungen'];

node[amenity=restaurant](area);

foreach {
   make x
      ::id = u(id()),
      lat  = u(lat()),
      lon  = u(lon()),
      name = u(t['name']);

   out geom;
}

[out:json];

area[name='Pfungen'];

node[amenity=restaurant](area);

foreach {
   make x
      ::id   =     u(id ()),
      ::geom = pt( u(lon()), u(lat())),
      name   =     u(t['name']);

   out geom;
}
[out:json];

area[name='Pfungen'];

node[amenity=restaurant][name=Linde     ](area) -> .linde;
node[amenity=restaurant][name=Schlosshof](area) -> .schlosshof;

make x
     dLon = linde.u(lon()) - schlosshof.u(lon()),
     dLat = linde.u(lat()) - schlosshof.u(lat());

out;

keys

Select a given object's keys (tags) and associated value:
[out:csv('key', 'val'; false)];

{{geocodeArea: Pfungen }};

node[amenity=library](area);

for (keys()) (
   make x key=_.val,
          val=u(t[_.val]);
   out;
);

length

Determine the number of ways in Pfungen with tag highway and sum up their lengths:
[out:csv(cnt, len)];

{{geocodeArea: Pfungen }};

way [ highway ]( area );

make x
  cnt    = count(ways    ),
  len    = sum  (length());

out;
Determine the length of each way in Pfungen whose highway tag is either residential or primary.
Use set(id)) to print (semicolon separated) all segment (way) id's with the same name value.
[out: csv(name, length, tag, ways) ];

{{geocodeArea: Pfungen }} -> .pfungen;

way
   (area.pfungen)
   [highway ~ '^(residential|primary)$' ]
   [name                                ] -> .highways;


for.highways (t['name']) {
    
  make x
    name      = _.val,
    length    = sum(length()),
    tag       = min(t['highway']), // Assume all segments have same highway value…
    ways      = set(id());
  out;
}
According to OpenStreetMap, the length of the Swiss border is 1938 km (while per Wikipedia, it is 1899 km):
[out:csv(lenBorder; false)];

area ['name:en' = 'Switzerland'];
rel(pivot);

make x lenBorder = sum(length()/1000);

out;

pt

make node
   ::geom=pt(42, 17);

out geom;
Creates
<node id="1">
  <point lat="42.0000000" lon="17.0000000"/>
</xyz>
It would, IMHO, be desirable if it created <node id="1" lat="41.0000000" lon="17.0000000"/>.

count_tags

Find nodes with more than 20 tags.
{{geocodeArea: Winterthur}};

// nwr
   node
     (area)
     (if: count_tags() > 20);

out geom;

is_closed

Find closed ways in Winterthur.
Since most (all?) buildings are closed anyway, filter them out:
{{geocodeArea: Winterthur}};

way
   [!building]
   (area)
   (if: is_closed() == 1);

out geom;

poly

{{N= 47.79 }}
{{S= 45.74 }}
{{E=  5.89 }}
{{W= 10.65 }}

[out:json];
make bb_ch
   ::geom=poly(lstr(
     pt( {{S}}, {{E}}),
     pt( {{N}}, {{E}}),
     pt( {{N}}, {{W}}),
     pt( {{S}}, {{W}}),
     pt( {{S}}, {{E}})
   ));

out geom;
Run on https://olbricht.nrw/ovt/ to visualize created geometry.

See also

Overpass API

Index