|
| 1 | +Overpass API python wrapper |
| 2 | +=========================== |
| 3 | + |
| 4 | +This is a thin wrapper around the OpenStreetMap `Overpass |
| 5 | +API <http://wiki.openstreetmap.org/wiki/Overpass_API>`__. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +Install it |
| 11 | +========== |
| 12 | + |
| 13 | +`pip install overpass` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Simplest example: |
| 18 | + |
| 19 | +```python |
| 20 | +import overpass |
| 21 | +api = overpass.API() |
| 22 | +response = api.Get('node["name"="Salt Lake City"]') |
| 23 | +``` |
| 24 | + |
| 25 | +Note that you don't have to include any of the output meta statements. |
| 26 | +The wrapper will, well, wrap those. |
| 27 | + |
| 28 | +You will get your result as a dictionary, which represents the |
| 29 | +JSON output you would get [from the Overpass API |
| 30 | +directly](http://overpass-api.de/output_formats.html#json>). So you |
| 31 | +could do this for example: |
| 32 | + |
| 33 | +```python |
| 34 | +print [(feature['tags']['name'], feature['id']) for feature in response['elements']] |
| 35 | +[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]``` |
| 36 | + |
| 37 | +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. |
| 38 | + |
| 39 | +```python |
| 40 | +response = api.Get('node["name"="Salt Lake City"]', responseformat="xml") |
| 41 | +``` |
| 42 | + |
| 43 | +### Parameters |
| 44 | + |
| 45 | + |
| 46 | +The API object takes a few parameters: |
| 47 | + |
| 48 | +#### endpoint |
| 49 | + |
| 50 | +The default endpoint is `http://overpass-api.de/api/interpreter` but |
| 51 | +you can pass in another instance: |
| 52 | + |
| 53 | +```python |
| 54 | +api = overpass.API(endpoint=http://overpass.myserver/interpreter) |
| 55 | +``` |
| 56 | + |
| 57 | +#### timeout |
| 58 | + |
| 59 | +The default timeout is 25 seconds, but you can set it to whatever you |
| 60 | +want. |
| 61 | + |
| 62 | +```python |
| 63 | +api = overpass.API(timeout=600) |
| 64 | +``` |
| 65 | + |
| 66 | +#### debug |
| 67 | + |
| 68 | +Setting this to `True` will get you debug output. |
| 69 | + |
| 70 | +### Simple queries |
| 71 | + |
| 72 | +In addition to just send your query and parse the result, the wrapper |
| 73 | +provides shortcuts for often used map queries. To use them, just pass |
| 74 | +them like to normal query to the API. |
| 75 | + |
| 76 | +#### MapQuery |
| 77 | + |
| 78 | +This is a shorthand for a `complete ways and |
| 79 | +relations <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations>`__ |
| 80 | +query in a bounding box (the 'map call'). You just pass the bounding box |
| 81 | +to the constructor: |
| 82 | + |
| 83 | +```python |
| 84 | +map_query = overpass.MapQuery(50.746,7.154,50.748,7.157) |
| 85 | +response = api.Get(map_query)``` |
| 86 | + |
| 87 | +#### WayQuery |
| 88 | + |
| 89 | +This is shorthand for getting a set of ways and their child nodes that |
| 90 | +satisfy certain criteria. Pass the criteria as a Overpass QL stub to the |
| 91 | +constructor: |
| 92 | + |
| 93 | +```python |
| 94 | +way_query = overpass.WayQuery('[name="Highway 51"]') |
| 95 | +response = api.Get(way_query)``` |
| 96 | + |
| 97 | +## Testing |
| 98 | + |
| 99 | +Using `nose`. |
| 100 | + |
| 101 | +`py.test` |
| 102 | + |
| 103 | +## FAQ |
| 104 | + |
| 105 | +### I need help or have an idea for a feature |
| 106 | + |
| 107 | +Create a [new |
| 108 | +issue](https://github.com/mvexel/overpass-api-python-wrapper/issues>). |
| 109 | + |
| 110 | +### Where did the CLI tool go? |
| 111 | + |
| 112 | +I decided that it does not belong in this repo. If you still want it, get version 0.4.0 or below. |
0 commit comments