drolbr/Overpass-API — pull request #135 by mmd-osm (2014-09-24 18:29:24+00:00)
Title: CSV output mode

After reading threads like [this one](http://forum.openstreetmap.org/viewtopic.php?id=25430) or [that one](http://gis.19327.n5.nabble.com/OSM-2-CSV-l-open-data-d-OSM-pour-tous-publics-tp5788744p5788827.html), I think it would be beneficial to provide a csv output mode right in Overpass API. This would enable users to immediately enter an URL in Excel/R/... and use the Overpass API result without further ado.

Is this a reasonable assumption?

Now, from the requirements point of view osmconvert seems to be a good starting point with options to toggle headline, change the separator chararcter and a list of columns to print (including some artificial ones). Also the format is well known in the OSM community.

--csv-headline
Choose this option to print a headline to csv output.

--csv-separator=
You may change the default separator (Tab) to a different
character or character sequence. For example:
--csv-separator="; "

--csv=
If you want to have certain columns in your csv list, please
specify their names as shown in this example:
--csv="@id name ref description"
There are a few special column names for header data:
@otype (object type 0..2), @oname (object type name), @id
@lon, @lat, @version, @timestamp, @changeset, @uid, @user

Additional questions:

* How to include new geometries: use a way's center point as @ lon/lat?
* Do we need additional escaping of column contents? Should the based on [RFC 4180](http://tools.ietf.org/html/rfc4180)? osmconvert uses a rather simple logic. Replace the separator character or any new line character by a replacement character: a space - or - underscore, if space was already used as separator character).
* Don't provide support for generic mode as column names are not known upfront and we don't want to cache the whole result
* How should the language look like?
[Custom and Popup output modes](http://overpass-api.de/output_formats.html) implement quite a number of features, which could also be useful for csv output. In Popup mode, the output specification is embedded right in the [out:*] declaration. As a very rough idea, the following syntax might be used.

`
[out:csv("@id name ref description", true, ",")]
`

I'm assuming that we define at most one global csv output structure which is then valid for each `out;` statement.
`