Overpass API python wrapper
Python bindings for the OpenStreetMap Overpass API.
pip install overpass
import overpass api = overpass.API() response = api.get('node["name"="Salt Lake City"]')
response will be a dictionary representing the
JSON output you would get from the Overpass API
Note that the Overpass query passed to
get() should not contain any
out or other meta statements.
>>> print [( ... feature['properties']['name'], ... feature['id']) for feature in response["features"]] [(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637)]
You can find more examples in the
examples/ directory of this repository.
You can set the response type of your query using
responseformat parameter to GeoJSON (
geojson, the default), plain JSON (
json), CSV (
csv), and OSM XML (
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
The API object takes a few parameters:
The default endpoint is
you can pass in another instance:
api = overpass.API(endpoint=https://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 sending your query and parse the result,
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:
MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157) response = api.get(MapQuery)
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:
WayQuery = overpass.WayQuery('[name="Highway 51"]') response = api.get(WayQuery)
I need help or have an idea for a feature
Create a new issue.
Where did the CLI tool go?
The command line tool was deprecated in version 0.4.0.