Skip to content

Commit f99f3fc

Browse files
committed
merging pep8 changes from mvexel#19
1 parent e74316f commit f99f3fc

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ $ python setup.py install
1212

1313
The module is not on PyPi yet.
1414

15+
If you get an error similar to
16+
17+
```
18+
OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
19+
```
20+
21+
you can install the required libraries on linux with
22+
```
23+
$ sudo apt-get install libgeos-c1 libgeos-3.4.2
24+
```
25+
1526
## Use it
1627

1728
```python
@@ -53,13 +64,9 @@ api = overpass.API(timeout=600)
5364

5465
Setting this to `True` will get you debug output.
5566

56-
#### `bbox`
57-
58-
This takes a list in the form `[minlon, minlat, maxlon, maxlat]`, the default is the world: `[-180.0, -90.0, 180.0, 90.0]`
59-
6067
### Simple queries
6168

62-
In addition to just send you query and parse it, the wrapper provides shortcuts for often used map queries. To use them, just pass them like to normal query to the API.
69+
In addition to just send your query and parse the result, the wrapper provides shortcuts for often used map queries. To use them, just pass them like to normal query to the API.
6370

6471
#### MapQuery
6572

overpass/api.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import requests
33
import json
4-
import geojson
4+
from shapely.geometry import Point
55

66
class API(object):
77
"""A simple Python wrapper for the OpenStreetMap Overpass API"""
@@ -11,17 +11,18 @@ class API(object):
1111
_endpoint = "http://overpass-api.de/api/interpreter"
1212
_responseformat = "json"
1313
_debug = False
14-
_bbox = [-180.0, -90.0, 180.0, 90.0]
1514

1615
_QUERY_TEMPLATE = "[out:{responseformat}];{query}out body;"
1716
_GEOJSON_QUERY_TEMPLATE = "[out:json];{query}out body geom;"
1817

1918
def __init__(self, *args, **kwargs):
2019
self.endpoint = kwargs.get("endpoint", self._endpoint)
2120
self.timeout = kwargs.get("timeout", self._timeout)
22-
self.responseformat = kwargs.get("responseformat", self._responseformat)
21+
self.responseformat = kwargs.get(
22+
"responseformat",
23+
self._responseformat
24+
)
2325
self.debug = kwargs.get("debug", self._debug)
24-
self.bbox = kwargs.get("bbox", self._bbox)
2526
self._status = None
2627

2728
if self.debug:
@@ -48,7 +49,10 @@ def Get(self, query, asGeoJSON=False):
4849
sys.exit(1)
4950

5051
if "elements" not in response or len(response["elements"]) == 0:
51-
raise OverpassException(204, 'No OSM features satisfied your query')
52+
raise OverpassException(
53+
204,
54+
'No OSM features satisfied your query'
55+
)
5256

5357
if not asGeoJSON:
5458
return response
@@ -65,13 +69,10 @@ def _ConstructQLQuery(self, userquery, asGeoJSON=False):
6569
if not raw_query.endswith(";"):
6670
raw_query += ";"
6771

68-
if asGeoJSON:
69-
template = self._GEOJSON_QUERY_TEMPLATE
70-
else:
71-
template = self._QUERY_TEMPLATE
72-
73-
complete_query = template.format(responseformat=self.responseformat, query=raw_query)
74-
72+
complete_query = self._QUERY_TEMPLATE.format(
73+
responseformat=self.responseformat,
74+
query=raw_query
75+
)
7576
if self.debug:
7677
print(complete_query)
7778
return complete_query
@@ -83,12 +84,20 @@ def _GetFromOverpass(self, query):
8384
payload = {"data": query}
8485

8586
try:
86-
r = requests.get(self.endpoint, params=payload, timeout=self.timeout)
87+
r = requests.get(
88+
self.endpoint,
89+
params=payload,
90+
timeout=self.timeout
91+
)
8792
except requests.exceptions.Timeout:
88-
raise OverpassException(408,
89-
'Query timed out. API instance is set to time out in {timeout} seconds. '
90-
'Try passing in a higher value when instantiating this API:'
91-
'api = Overpass.API(timeout=60)'.format(timeout=self.timeout))
93+
raise OverpassException(
94+
408,
95+
'Query timed out. API instance is set to time out in {timeout}'
96+
' seconds. Try passing in a higher value when instantiating'
97+
' this API: api = Overpass.API(timeout=60)'.format(
98+
timeout=self.timeout
99+
)
100+
)
92101

93102
self._status = r.status_code
94103

@@ -131,4 +140,7 @@ def __init__(self, status_code, message):
131140
self.message = message
132141

133142
def __str__(self):
134-
return json.dumps({'status': self.status_code, 'message': self.message})
143+
return json.dumps({
144+
'status': self.status_code,
145+
'message': self.message
146+
})

overpass/queries.py

100755100644
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ class MapQuery(object):
1010
def __init__(self, south, west, north, east):
1111
"""
1212
Initialize query with given bounding box.
13-
:param bbox Bounding box with limit values in format west, south, east, north.
13+
:param bbox Bounding box with limit values in format west, south,
14+
east, north.
1415
"""
1516
self.west = west
1617
self.south = south
1718
self.east = east
1819
self.north = north
1920

2021
def __str__(self):
21-
return self._QUERY_TEMPLATE.format(west=self.west, south=self.south, east=self.east, north=self.north)
22+
return self._QUERY_TEMPLATE.format(
23+
west=self.west,
24+
south=self.south,
25+
east=self.east,
26+
north=self.north
27+
)
2228

2329

2430
class WayQuery(object):
2531

26-
"""Query to retrieve a set of ways and their dependent nodes satisfying the input parameters"""
32+
"""Query to retrieve a set of ways and their dependent nodes satisfying
33+
the input parameters"""
2734

2835
_QUERY_TEMPLATE = "(way{query_parameters});(._;>;);"
2936

@@ -35,4 +42,6 @@ def __init__(self, query_parameters):
3542
self.query_parameters = query_parameters
3643

3744
def __str__(self):
38-
return self._QUERY_TEMPLATE.format(query_parameters=self.query_parameters)
45+
return self._QUERY_TEMPLATE.format(
46+
query_parameters=self.query_parameters
47+
)

test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import geojson
22
import overpass
33

4-
class TestAPI:
4+
5+
class TestAPI(object):
56

67
def test_initialize_api(self):
78
api = overpass.API()

0 commit comments

Comments
 (0)