This is a thin wrapper around the OpenStreetMap Overpass API.
pip install overpass
Simplest example:
import overpass
api = overpass.API()
response = api.Get('node["name"="Salt Lake City"]')
Note that you don't have to include any of the output meta statements. The wrapper will, well, wrap those.
You will get your result as a dictionary, which represents the JSON output you would get from the Overpass API directly. So you could do this for example:
print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
You can specify the format of the response. By default, you will get GeoJSON using the responseformat
parameter. Alternatives are plain JSON (json
) and OSM XML (xml
), as ouput directly by the Overpass API.
response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
The API object takes a few parameters:
The default endpoint is http://overpass-api.de/api/interpreter
but
you can pass in another instance:
api = overpass.API(endpoint=http://overpass.myserver/interpreter)
The default timeout is 25 seconds, but you can set it to whatever you want.
api = overpass.API(timeout=600)
Setting this to True
will get you debug output.
In addition to just send your query and parse the result, the wrapper provides shortcuts for often used map queries. To use them, just pass them like to normal query to the API.
This is a shorthand for a complete ways and relations query in a bounding box (the 'map call'). You just pass the bounding box to the constructor:
map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
response = api.Get(map_query)
This is shorthand for getting a set of ways and their child nodes that satisfy certain criteria. Pass the criteria as a Overpass QL stub to the constructor:
way_query = overpass.WayQuery('[name="Highway 51"]')
response = api.Get(way_query)
Using nose
.
py.test
Create a new issue.
I decided that it does not belong in this repo. If you still want it, get version 0.4.0 or below.