Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit ce19e14

Browse files
committed
Merge pull request #36 from mvexel/merge-wille
Merge Wille's fork and improvements
2 parents 47c477f + 34a2dc0 commit ce19e14

File tree

13 files changed

+371
-176
lines changed

13 files changed

+371
-176
lines changed

.gitignore

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
*~
22
*.swp
33
.DS_Store
4-
*.pyc
54

6-
/build/
7-
/dist/
8-
/*.egg-info
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
env/
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.coverage
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
55+
# Sphinx documentation
56+
docs/_build/
57+
58+
# PyBuilder
59+
target/

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ language: python
22
python:
33
- "2.6"
44
- "2.7"
5-
- "3.2"
65
- "3.3"
76
- "3.4"
8-
install: "python setup.py install"
7+
- "3.5"
8+
install:
9+
- "pip install ."
910
# command to run tests
10-
script: python test_api.py
11+
script: py.test
1112
notifications:
1213
email: false

README.md

Lines changed: 0 additions & 106 deletions
This file was deleted.

README.rst

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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+
.. image:: https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg
8+
:target: https://travis-ci.org/mvexel/overpass-api-python-wrapper
9+
10+
11+
Install it
12+
==========
13+
14+
.. code:: bash
15+
16+
$ pip install overpass
17+
18+
If you get an error similar to
19+
20+
::
21+
22+
OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
23+
24+
you can install the required libraries on linux with
25+
26+
.. code:: bash
27+
28+
$ sudo apt-get install libgeos-c1 libgeos-3.4.2
29+
30+
Use it
31+
======
32+
33+
You can use the overpass command line interface or use it as a Python
34+
library.
35+
36+
Command line interface
37+
---------------------
38+
39+
You can use the CLI to execute queries and save the result in a GeoJSON
40+
file.
41+
42+
::
43+
44+
Usage: overpass [OPTIONS] QUERY OUTPUT_FILE
45+
46+
Run query and save the result in output_file
47+
48+
Options:
49+
--timeout INTEGER Timeout in seconds
50+
--endpoint TEXT URL of your prefered API
51+
--format TEXT Format to save the data. Options are 'geojson', 'json', 'xml'. Default format is geojson.
52+
--help Show this message and exit.
53+
54+
For example:
55+
56+
To make a query and save the result as GeoJSON:
57+
58+
.. code:: bash
59+
60+
overpass --timeout 50 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.geojson
61+
62+
Or to get the result as an OSM XML file:
63+
64+
.. code:: bash
65+
66+
overpass --timeout 50 --format xml 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.osm
67+
68+
Python Library
69+
-------------
70+
71+
.. code:: python
72+
73+
>>> import overpass
74+
>>> api = overpass.API()
75+
>>> response = api.Get('node["name"="Salt Lake City"]')
76+
77+
Note that you don't have to include any of the output meta statements.
78+
The wrapper will, well, wrap those.
79+
80+
You will get your result as a dictionary, which (for now) represents the
81+
JSON output you would get `from the Overpass API
82+
directly <http://overpass-api.de/output_formats.html#json>`__. So you
83+
could do this for example:
84+
85+
.. code:: python
86+
87+
>>> print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
88+
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
89+
90+
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.
91+
92+
.. code:: python
93+
94+
>>> import overpass
95+
>>> api = overpass.API()
96+
>>> response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
97+
98+
Parameters
99+
~~~~~~~~~~
100+
101+
The API takes a few parameters:
102+
103+
``endpoint``
104+
^^^^^^^^^^
105+
106+
The default endpoint is ``http://overpass-api.de/api/interpreter`` but
107+
you can pass in the rambler instance
108+
(``http://overpass.osm.rambler.ru/cgi/interpreter``) or your own:
109+
110+
.. code:: python
111+
112+
api = overpass.API(endpoint=http://overpass.myserver/interpreter)
113+
114+
``timeout``
115+
^^^^^^^^^^
116+
117+
The default timeout is 25 seconds, but you can set it to whatever you
118+
want.
119+
120+
.. code:: python
121+
122+
api = overpass.API(timeout=600)
123+
124+
``debug``
125+
^^^^^^^^^^
126+
127+
Setting this to ``True`` will get you debug output.
128+
129+
Simple queries
130+
~~~~~~~~~~~
131+
132+
In addition to just send your query and parse the result, the wrapper
133+
provides shortcuts for often used map queries. To use them, just pass
134+
them like to normal query to the API.
135+
136+
MapQuery
137+
^^^^^^^^
138+
139+
This is a shorthand for a `complete ways and
140+
relations <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations>`__
141+
query in a bounding box (the 'map call'). You just pass the bounding box
142+
to the constructor:
143+
144+
.. code:: python
145+
146+
>>> map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
147+
>>> response = api.Get(map_query)
148+
149+
WayQuery
150+
^^^^^^^^
151+
152+
This is shorthand for getting a set of ways and their child nodes that
153+
satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
154+
constructor:
155+
156+
.. code:: python
157+
158+
>>> way_query = overpass.WayQuery('[name=Highway 51]')
159+
>>> response = api.Get(way_query)
160+
161+
Need help? Want feature?
162+
=======================
163+
164+
Create a `new
165+
issue <https://github.com/mvexel/overpass-api-python-wrapper/issues>`__.
166+
167+
Test it
168+
-------
169+
170+
::
171+
172+
py.test
173+
174+
Fork it
175+
-------
176+
177+
`Yes
178+
please <https://github.com/mvexel/overpass-api-python-wrapper/fork>`__.
179+
`Help
180+
wanted <https://github.com/mvexel/overpass-api-python-wrapper/labels/help%20wanted>`__.

0 commit comments

Comments
 (0)