- 00 - The Beginning
- 01 - Finding nodes with a bounding box
- 02 - Outputting data about nodes
- 03 - Filtering nodes that have a tag
- 04 - Find nodes by matching tags and their values
- 05 - Find nodes by applying multiple filters
- 06 - Extracting multiple sets of nodes
- 07 - Calculating differences between results
- 08 - Generating JSON output
- 09 - Generating CSV output
- 10 - The default set
- 11 - Querying a set
- 12 - Searching within a radius using around
- 13 - Using around to filter against a set of results
- 14 - Searching by polygon
- 15 - Finding ways
- 16 - Ways and their nodes
- 17 - Ways and their tags
- 18 - Combining node and way queries
- 19 - Finding ways from their nodes
- 20 - Finding relations
- 21 - Type agnostic queries (nwr)
- 22 - Areas
- 23 - Finding the areas enclosing a feature
- 24 - Find the area derived from a feature
- 25 - Areas via Nominatim search
- 26 - Timeouts and endpoints
09 - Generating CSV output
OverpassQL can also be used to generate simple CSV exports.
This is achieved by using the
[out:csv] query setting.
In order for the API to know how to construct the CSV output you must provide a specification of what fields (columns) to include. These fields are either:
- a special field name, which is predefined by the API, e.g.
- or the name of a tag
The special field names include:
::id- the database id of the object
::type- its type, e.g. node, way or relation
::lat- its latitude
::lon- its longitude
The list of columns to include in the output are specified as parameters in the query setting statement.
Other parameters allow you to customise whether a header line is included in the CSV file and choose the column separator. The defaults are to include a header and produce a tab delimited file.
The general syntax for the
out:csv setting is:
[out:csv (columns; header; col-separator)]
columnsis a comma separated list of names
col-separatoris the desired separator provided as a string.
This query generates a simple comma-separated table containing the
and names of caves within the bounding box. But some other variations are also provided for
you to try out.
If you want to include tags in your CSV output, then the
out keyword of your
query must generate tags. So use
out body or
Also note that when you're including latitude (
::lat) and longitude (
columns then for nodes you'll get their original coordinates. But ways and relations are
more complex spatial objects. They aren't defined by a single point.
You can use the
out keyword to automatically generate a representative location (a "centroid")
for those types of feature. Specifying
out body center will do the trick. This will calculate
a centroid for any way or relation in your results.
Tip: when generating CSV output, if there is a query error or timeout then you will get empty results. I'd recommend writing and testing your basic query first so you're sure it's working. And then customise it further to generate the desired CSV output.