User:Tagtheworld/overpass-api commandline

From OpenStreetMap Wiki
Jump to: navigation, search

Command line :: Perform a Download

all the texts are taken from the manual at [1]

they note: To download data (by hand or in a script) from Overpass API, you can use for example the well-known program wget. Alternatives are for example curl or, in case of FreeBSD, fetch. We assume here that you plan to use it in a script or other non-interactive way, because otherwise the query form might be a more convenient alternative.

The possible formats of the downloaded file are described on the output formats page.

For short queries, the usage is very simple: Just write the query in the command line:

wget "[name=\"Gielgen\"];out;"

Please note that we need to escape the quotation mark ("). Because we have enclosed the URL in quotation marks, we must escape only two more characters: the dollar ($) sign should get (\$) and the backslash (\) should be doubled (\\).

In most cases it would be helpful to store the results with a meaningful filename. Use -O for that purpose:

wget -O target.osm "[name=\"Gielgen\"];out;"

For longer queries, it could be helpful to have the query in a separate file. That is also possible:

echo "data=node[name=\"Gielgen\"];out;" >query.osm
wget -O target.osm --post-file=query.osm ""

A subtle detail you may have recognized in the last example is the prefix data=. This can be omitted, but has slightly different meaning: If the data= prefix is present, then Overpass API assumes the query behind this prefix is URL encoded. This is what usually happens when it comes from a HTML form and sometimes by some HTTP clients. If you omit the prefix, Overpass API takes the data to be verbatim and does no URL deocding.

HTTP methods and headers

Overpass API accepts both HTTP GET and HTTP POST requests. Both are handled as similar as possible, so we treat them together. Additionally, Overpass API handles HTTP OPTIONS requests. We explain the details in the last paragraph.

...see more at the excellent manuals at