csv
[out:csv(
num, txt ; // Column names
true ; // header (true is default)
"|" // separator
)];
make foo // <--- the type / if output is xml, it becomes the XML's tag name
num = 42,
txt ='Hello world';
out;
(Mis-)using CSV output to generate text result
[out:csv(txt; false)];
{{geocodeArea: Pfungen }};
//
// Search for amenities with a name in the
// selected area:
//
nw[amenity][name](area) -> .amenities;
//
// Iterate over each amenity type (restaurant, doctor etc.)
//
for.amenities -> .amenity (t['amenity']) {
//
// Print name of amenity type
//
make x txt = amenity.val; out;
//
// Iterate over each amenity within the type:
//
foreach.amenity {
//
// Print the amenity's id, type and name:
//
make x txt = ' ' + u(id()) + ' (' + u(type()) + '): ' + u(t['name']); out;
}
//
// Finish amenity type with an empty line:
//
make x txt = ''; out;
}
Get tramway colors of VBZ (Verkehrsbetriebe Zürich)
[out:csv(ref, colour)];
relation
[operator = 'Verkehrsbetriebe Zürich']
[route = 'tram' ];
out;
Unfortunately, the same line (and color value) are returned multiple times, but we want a unique (distinct) list. The following query will achieve this:
[out:csv(ref, colour)];
relation[operator='Verkehrsbetriebe Zürich'][route='tram'];
for (t['ref']) {
make x
ref = _.val,
colour = u(t['colour']);
out;
}
json
[out:json]
returns the result of a query in
JSON format.
[out:json];
{{geocodeArea:Pfungen}};
nwr(area);
out;
The generated result looks something like
{
"version": 0.6,
"generator": "Overpass API 0.7.59 e21c39fe",
"osm3s": {
"timestamp_osm_base": "2022-10-16T14:17:49Z",
"timestamp_areas_base": "2022-10-16T13:56:25Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "node",
"id": 17288816,
"lat": 47.5168632,
"lon": 8.6259800
},
…
{
"type": "node",
"id": 17288830,
"lat": 47.5164709,
"lon": 8.6323133,
"tags": {
"maxspeed": "60",
"traffic_sign": "city_limit"
}
},
…
{
"type": "way",
"id": 46978812,
"nodes": [
1307209867,
276423681
],
"tags": {
"highway": "track",
"name": "Klosterruinenstrasse",
"tracktype": "grade2"
}
},
…
]
}