Skip to content

Commit 171fcf3

Browse files
author
Lukas Müller
committed
Merge branch 'master' into relation_and_multipolygon_support
# Conflicts: # overpass/api.py
2 parents 51c4ae9 + c28b3c0 commit 171fcf3

21 files changed

+653
-232
lines changed

.gitignore

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,14 @@
1-
*~
2-
*.swp
31
.DS_Store
4-
5-
# Byte-compiled / optimized / DLL files
6-
__pycache__/
2+
.pytest_cache/
3+
**/__pycache__/
74
*.py[cod]
8-
9-
# C extensions
10-
*.so
11-
12-
# Distribution / packaging
13-
.Python
14-
env/
15-
build/
16-
develop-eggs/
175
dist/
18-
downloads/
6+
build/
197
eggs/
208
.eggs/
21-
lib/
22-
lib64/
23-
parts/
24-
sdist/
25-
var/
269
*.egg-info/
27-
.installed.cfg
2810
*.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
3711
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
5612
docs/_build/
57-
58-
# PyBuilder
59-
target/
13+
Pipfile.lock
14+
venv/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: python
22
python:
3-
- "2.6"
43
- "2.7"
54
- "3.3"
65
- "3.4"
76
- "3.5"
7+
- "3.6"
88
install:
99
- "pip install ."
1010
# command to run tests

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include LICENSE.txt
2+
include tests/*
3+
include examples/*

Pipfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
geojson = ">=1.3.1"
8+
requests = ">=2.20.0"
9+
nose = ">=1.3.7"
10+
11+
[dev-packages]
12+
13+
[requires]

README.md

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Overpass API python wrapper
22
===========================
33

4-
This is a thin wrapper around the OpenStreetMap [Overpass
5-
API](http://wiki.openstreetmap.org/wiki/Overpass_API>).
4+
Python bindings for the OpenStreetMap [Overpass
5+
API](http://wiki.openstreetmap.org/wiki/Overpass_API).
66

77
[![Build Status](https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg?branch=master)](https://travis-ci.org/mvexel/overpass-api-python-wrapper)
88

@@ -13,76 +13,107 @@ Install it
1313

1414
## Usage
1515

16-
Simplest example:
16+
### `API()` constructor
17+
18+
First, create an API object.
1719

1820
```python
1921
import overpass
2022
api = overpass.API()
21-
response = api.Get('node["name"="Salt Lake City"]')
2223
```
2324

24-
Note that you don't have to include any of the output meta statements.
25-
The wrapper will, well, wrap those.
25+
The API constructor takes several parameters, all optional:
2626

27-
You will get your result as a dictionary, which represents the
28-
JSON output you would get [from the Overpass API
29-
directly](http://overpass-api.de/output_formats.html#json>). So you
30-
could do this for example:
27+
#### `endpoint`
28+
29+
The default endpoint is `https://overpass-api.de/api/interpreter` but
30+
you can pass in another instance:
3131

3232
```python
33-
print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
34-
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
33+
api = overpass.API(endpoint="https://overpass.myserver/interpreter")
3534
```
3635

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.
36+
#### `timeout`
37+
38+
The default timeout is 25 seconds, but you can set it to whatever you
39+
want.
3840

3941
```python
40-
response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
42+
api = overpass.API(timeout=600)
4143
```
4244

43-
### Parameters
45+
#### `debug`
4446

47+
Setting this to `True` will get you debug output.
4548

46-
The API object takes a few parameters:
49+
### Getting data from Overpass: `get()`
4750

48-
#### endpoint
51+
Most users will only ever need to use the `get()` method. There are some convenience query methods for common queries as well, see below.
4952

50-
The default endpoint is `http://overpass-api.de/api/interpreter` but
51-
you can pass in another instance:
53+
```python
54+
response = api.get('node["name"="Salt Lake City"]')
55+
```
56+
57+
`response` will be a dictionary representing the
58+
JSON output you would get [from the Overpass API
59+
directly](https://overpass-api.de/output_formats.html#json).
60+
61+
**Note that the Overpass query passed to `get()` should not contain any `out` or other meta statements.** See `verbosity` below for how to control the output.
62+
63+
Another example:
5264

5365
```python
54-
api = overpass.API(endpoint=http://overpass.myserver/interpreter)
66+
>>> print [(
67+
... feature['properties']['name'],
68+
... feature['id']) for feature in response["features"]]
69+
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637)]
5570
```
5671

57-
#### timeout
72+
You can find more examples in the `examples/` directory of this repository.
5873

59-
The default timeout is 25 seconds, but you can set it to whatever you
60-
want.
74+
The `get()` method takes a few parameters, all optional having sensible defaults.
75+
76+
#### `verbosity`
77+
78+
You can set the verbosity of the [Overpass query `out` directive](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#out) using the same keywords Overpass does. In order of increased verbosity: `ids`, `skel`, `body`, `tags`, `meta`. As is the case with the Overpass API itself, `body` is the default.
6179

6280
```python
63-
api = overpass.API(timeout=600)
81+
>>> import overpass
82+
>>> api = overpass.API()
83+
>>> data = api.get('way(42.819,-73.881,42.820,-73.880);(._;>;)', verbosity='geom')
84+
>>> [f for f in data.features if f.geometry['type'] == "LineString"]
6485
```
6586

66-
#### debug
87+
(from [a question on GIS Stackexchange](https://gis.stackexchange.com/questions/294152/getting-all-information-about-ways-from-python-overpass-library/294358#294358))
6788

68-
Setting this to `True` will get you debug output.
89+
#### `responseformat`
90+
91+
You can set the response type of your query using `get()`'s `responseformat` parameter to GeoJSON (`geojson`, the default), plain JSON (`json`), CSV (`csv`), and OSM XML (`xml`).
92+
93+
```python
94+
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
95+
```
96+
97+
#### `build`
98+
99+
We will construct a valid Overpass QL query from the parameters you set by default. This means you don't have to include 'meta' statements like `[out:json]`, `[timeout:60]`, `[out body]`, etcetera. You just supply the meat of the query, the part that actually tells Overpass what to query for. If for whatever reason you want to override this and supply a full, valid Overpass QL query, you can set `build` to `False` to make the API not do any pre-processing.
69100

70-
### Simple queries
101+
### Pre-cooked Queries: `MapQuery`, `WayQuery`
71102

72-
In addition to just send your query and parse the result, the wrapper
103+
In addition to just sending your query and parse the result, `overpass`
73104
provides shortcuts for often used map queries. To use them, just pass
74105
them like to normal query to the API.
75106

76107
#### MapQuery
77108

78109
This is a shorthand for a [complete ways and
79-
relations](http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Recursing_up_and_down:_Completed_ways_and_relations)
110+
relations](https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Recursing_up_and_down:_Completed_ways_and_relations)
80111
query in a bounding box (the 'map call'). You just pass the bounding box
81112
to the constructor:
82113

83114
```python
84-
map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
85-
response = api.Get(map_query)
115+
MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157)
116+
response = api.get(MapQuery)
86117
```
87118

88119
#### WayQuery
@@ -92,13 +123,13 @@ satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
92123
constructor:
93124

94125
```python
95-
way_query = overpass.WayQuery('[name="Highway 51"]')
96-
response = api.Get(way_query)
126+
WayQuery = overpass.WayQuery('[name="Highway 51"]')
127+
response = api.get(WayQuery)
97128
```
98129

99130
## Testing
100131

101-
Using `nose`.
132+
Using `pytest`.
102133

103134
`py.test`
104135

@@ -107,8 +138,8 @@ Using `nose`.
107138
### I need help or have an idea for a feature
108139

109140
Create a [new
110-
issue](https://github.com/mvexel/overpass-api-python-wrapper/issues>).
141+
issue](https://github.com/mvexel/overpass-api-python-wrapper/issues).
111142

112143
### Where did the CLI tool go?
113144

114-
I decided that it does not belong in this repo. If you still want it, get version 0.4.0 or below.
145+
The command line tool was deprecated in version 0.4.0.

0 commit comments

Comments
 (0)