Skip to content

Commit 880c098

Browse files
committed
Added query to retrieve map.
1 parent 5989b01 commit 880c098

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Overpass/Overpass.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class API(object):
1313
_debug = False
1414
_bbox = [-180.0, -90.0, 180.0, 90.0]
1515

16+
_QUERY_TEMPLATE = "[out:{responseformat}];{query}out body;"
17+
1618
def __init__(self, *args, **kwargs):
1719
self.endpoint = kwargs.get("endpoint", self._endpoint)
1820
self.timeout = kwargs.get("timeout", self._timeout)
@@ -59,12 +61,14 @@ def _ConstructError(self, msg):
5961
}
6062

6163
def _ConstructQLQuery(self, userquery):
62-
if not userquery.endswith(";"):
63-
userquery += ";"
64-
fullquery = "[out:{responseformat}];".format(responseformat=self.responseformat) + userquery + "out body;"
64+
raw_query = str(userquery)
65+
if not raw_query.endswith(";"):
66+
raw_query += ";"
67+
68+
complete_query = self._QUERY_TEMPLATE.format(responseformat=self.responseformat, query=raw_query)
6569
if self.debug:
66-
print fullquery
67-
return "[out:{responseformat}];".format(responseformat=self.responseformat) + userquery + "out body;"
70+
print complete_query
71+
return complete_query
6872

6973
def _GetFromOverpass(self, query):
7074
"""This sends the API request to the Overpass instance and

Overpass/queries.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
class MapQuery(object):
5+
"""Query to retrieve complete ways and relations in an area."""
6+
7+
_QUERY_TEMPLATE = "(node({bbox[0]},{bbox[1]},{bbox[2]},{bbox[2]});<;>;);"
8+
9+
def __init__(self, bbox):
10+
"""
11+
Initialize query with given bounding box.
12+
:param bbox Bounding box with limit values in format (s, w, n, e) in a sequence.
13+
"""
14+
self.bbox = bbox
15+
16+
def __str__(self):
17+
return self._QUERY_TEMPLATE.format(bbox=self.bbox)

0 commit comments

Comments
 (0)