|
| 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 | +|Build Status| |
| 8 | + |
| 9 | +Install it |
| 10 | +========== |
| 11 | + |
| 12 | +``pip install overpass`` |
| 13 | + |
| 14 | +Usage |
| 15 | +----- |
| 16 | + |
| 17 | +Simplest example: |
| 18 | + |
| 19 | +.. code:: python |
| 20 | +
|
| 21 | + import overpass |
| 22 | + api = overpass.API() |
| 23 | + response = api.get('node["name"="Salt Lake City"]') |
| 24 | +
|
| 25 | +``response`` will be a dictionary representing the JSON output you would |
| 26 | +get `from the Overpass API |
| 27 | +directly <https://overpass-api.de/output_formats.html#json>`__. |
| 28 | + |
| 29 | +Note that the Overpass query passed to ``get()`` should not contain any |
| 30 | +``out`` or other meta statements. |
| 31 | + |
| 32 | +Another example: |
| 33 | + |
| 34 | +.. code:: python |
| 35 | +
|
| 36 | + >>> print [( |
| 37 | + ... feature['properties']['name'], |
| 38 | + ... feature['id']) for feature in response["features"]] |
| 39 | + [(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637)] |
| 40 | +
|
| 41 | +You can find more examples in the ``examples/`` directory of this |
| 42 | +repository. |
| 43 | + |
| 44 | +Response formats |
| 45 | +~~~~~~~~~~~~~~~~ |
| 46 | + |
| 47 | +You can set the response type of your query using ``get()``\ ’s |
| 48 | +``responseformat`` parameter to GeoJSON (``geojson``, the default), |
| 49 | +plain JSON (``json``), CSV (``csv``), and OSM XML (``xml``). |
| 50 | + |
| 51 | +.. code:: python |
| 52 | +
|
| 53 | + response = api.get('node["name"="Salt Lake City"]', responseformat="xml") |
| 54 | +
|
| 55 | +Parameters |
| 56 | +~~~~~~~~~~ |
| 57 | + |
| 58 | +The API object takes a few parameters: |
| 59 | + |
| 60 | +``endpoint`` |
| 61 | +^^^^^^^^^^^^ |
| 62 | + |
| 63 | +The default endpoint is ``https://overpass-api.de/api/interpreter`` but |
| 64 | +you can pass in another instance: |
| 65 | + |
| 66 | +.. code:: python |
| 67 | +
|
| 68 | + api = overpass.API(endpoint=https://overpass.myserver/interpreter) |
| 69 | +
|
| 70 | +``timeout`` |
| 71 | +^^^^^^^^^^^ |
| 72 | + |
| 73 | +The default timeout is 25 seconds, but you can set it to whatever you |
| 74 | +want. |
| 75 | + |
| 76 | +.. code:: python |
| 77 | +
|
| 78 | + api = overpass.API(timeout=600) |
| 79 | +
|
| 80 | +``debug`` |
| 81 | +^^^^^^^^^ |
| 82 | + |
| 83 | +Setting this to ``True`` will get you debug output. |
| 84 | + |
| 85 | +Simple queries |
| 86 | +~~~~~~~~~~~~~~ |
| 87 | + |
| 88 | +In addition to just sending your query and parse the result, the wrapper |
| 89 | +provides shortcuts for often used map queries. To use them, just pass |
| 90 | +them like to normal query to the API. |
| 91 | + |
| 92 | +MapQuery |
| 93 | +^^^^^^^^ |
| 94 | + |
| 95 | +This is a shorthand for a `complete ways and |
| 96 | +relations <https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Recursing_up_and_down:_Completed_ways_and_relations>`__ |
| 97 | +query in a bounding box (the ‘map call’). You just pass the bounding box |
| 98 | +to the constructor: |
| 99 | + |
| 100 | +.. code:: python |
| 101 | +
|
| 102 | + MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157) |
| 103 | + response = api.get(MapQuery) |
| 104 | +
|
| 105 | +WayQuery |
| 106 | +^^^^^^^^ |
| 107 | + |
| 108 | +This is shorthand for getting a set of ways and their child nodes that |
| 109 | +satisfy certain criteria. Pass the criteria as a Overpass QL stub to the |
| 110 | +constructor: |
| 111 | + |
| 112 | +.. code:: python |
| 113 | +
|
| 114 | + WayQuery = overpass.WayQuery('[name="Highway 51"]') |
| 115 | + response = api.get(WayQuery) |
| 116 | +
|
| 117 | +Testing |
| 118 | +------- |
| 119 | + |
| 120 | +Using ``pytest``. |
| 121 | + |
| 122 | +``py.test`` |
| 123 | + |
| 124 | +FAQ |
| 125 | +--- |
| 126 | + |
| 127 | +I need help or have an idea for a feature |
| 128 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 129 | + |
| 130 | +Create a `new |
| 131 | +issue <https://github.com/mvexel/overpass-api-python-wrapper/issues>`__. |
| 132 | + |
| 133 | +Where did the CLI tool go? |
| 134 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 135 | + |
| 136 | +The command line tool was deprecated in version 0.4.0. |
| 137 | + |
| 138 | +.. |Build Status| image:: https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg?branch=master |
| 139 | + :target: https://travis-ci.org/mvexel/overpass-api-python-wrapper |
0 commit comments