From 880c098090a93d1f32cb6c18d7f75d4a0fed03f0 Mon Sep 17 00:00:00 2001 From: Tim Bolender Date: Sat, 11 Oct 2014 17:31:02 +0200 Subject: [PATCH 1/4] Added query to retrieve map. --- Overpass/Overpass.py | 14 +++++++++----- Overpass/queries.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100755 Overpass/queries.py diff --git a/Overpass/Overpass.py b/Overpass/Overpass.py index 6eecd6649ea..b94d0bbc2f5 100644 --- a/Overpass/Overpass.py +++ b/Overpass/Overpass.py @@ -13,6 +13,8 @@ class API(object): _debug = False _bbox = [-180.0, -90.0, 180.0, 90.0] + _QUERY_TEMPLATE = "[out:{responseformat}];{query}out body;" + def __init__(self, *args, **kwargs): self.endpoint = kwargs.get("endpoint", self._endpoint) self.timeout = kwargs.get("timeout", self._timeout) @@ -59,12 +61,14 @@ def _ConstructError(self, msg): } def _ConstructQLQuery(self, userquery): - if not userquery.endswith(";"): - userquery += ";" - fullquery = "[out:{responseformat}];".format(responseformat=self.responseformat) + userquery + "out body;" + raw_query = str(userquery) + if not raw_query.endswith(";"): + raw_query += ";" + + complete_query = self._QUERY_TEMPLATE.format(responseformat=self.responseformat, query=raw_query) if self.debug: - print fullquery - return "[out:{responseformat}];".format(responseformat=self.responseformat) + userquery + "out body;" + print complete_query + return complete_query def _GetFromOverpass(self, query): """This sends the API request to the Overpass instance and diff --git a/Overpass/queries.py b/Overpass/queries.py new file mode 100755 index 00000000000..6f182523c50 --- /dev/null +++ b/Overpass/queries.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + + +class MapQuery(object): + """Query to retrieve complete ways and relations in an area.""" + + _QUERY_TEMPLATE = "(node({bbox[0]},{bbox[1]},{bbox[2]},{bbox[2]});<;>;);" + + def __init__(self, bbox): + """ + Initialize query with given bounding box. + :param bbox Bounding box with limit values in format (s, w, n, e) in a sequence. + """ + self.bbox = bbox + + def __str__(self): + return self._QUERY_TEMPLATE.format(bbox=self.bbox) \ No newline at end of file From 96dc92212827f6e5b36ba68b9ddf0320a2b643d8 Mon Sep 17 00:00:00 2001 From: Tim Bolender Date: Mon, 13 Oct 2014 22:08:01 +0200 Subject: [PATCH 2/4] Reduced map query to get only data in bounding box (see http://wiki.openstreetmap.org/wiki/Overpass_API#The_map_query). --- Overpass/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Overpass/queries.py b/Overpass/queries.py index 6f182523c50..19cb0dc43d6 100755 --- a/Overpass/queries.py +++ b/Overpass/queries.py @@ -4,7 +4,7 @@ class MapQuery(object): """Query to retrieve complete ways and relations in an area.""" - _QUERY_TEMPLATE = "(node({bbox[0]},{bbox[1]},{bbox[2]},{bbox[2]});<;>;);" + _QUERY_TEMPLATE = "(node({bbox[0]},{bbox[1]},{bbox[2]},{bbox[2]});<;);" def __init__(self, bbox): """ From 0f8d3f008c5c0e8e45c6a5c8a4622113ee1a14b2 Mon Sep 17 00:00:00 2001 From: Tim Bolender Date: Mon, 13 Oct 2014 22:21:16 +0200 Subject: [PATCH 3/4] Updated readme. --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index dd392731619..17be12248e0 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,21 @@ Setting this to `True` will get you debug output. This takes a list in the form `[minlon, minlat, maxlon, maxlat]`, the default is the world: `[-180.0, -90.0, 180.0, 90.0]` +### Simple queries + +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. + +#### MapQuery + +Up to now, only a query for [complete ways and relations](http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations) in a bounding box is supported. +You just pass the bounding box to the constructor: + +```python +>>> from overpass import queries +>>> map_query = queries.MapQuery((50.746,7.154,50.748,7.157)) +>>> response = api.Get(map_query) +``` + ## Need help? Want feature? Create a [new issue](https://github.com/mvexel/overpass-api-python-wrapper/issues). From 41847837661a0d5331b21a0ef5b65e4d6c545bf2 Mon Sep 17 00:00:00 2001 From: Tim Bolender Date: Tue, 14 Oct 2014 01:21:12 +0200 Subject: [PATCH 4/4] Added auto-import for queries and updated readme accordingly. --- README.md | 5 ++--- overpass/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 308cea033ae..f34f8bd9677 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,8 @@ Up to now, only a query for [complete ways and relations](http://wiki.openstreet You just pass the bounding box to the constructor: ```python ->>> from overpass import queries ->>> map_query = queries.MapQuery((50.746,7.154,50.748,7.157)) ->>> response = api.Get(map_query) +>>> map_query = overpass.MapQuery((50.746,7.154,50.748,7.157)) +>>> response = api.Get(map_query) ``` ## Need help? Want feature? diff --git a/overpass/__init__.py b/overpass/__init__.py index ff16d78e66c..744a7e0ba9e 100644 --- a/overpass/__init__.py +++ b/overpass/__init__.py @@ -6,4 +6,5 @@ __version__ = '0.0.1' __license__ = 'Apache 2.0' -from .api import API \ No newline at end of file +from .api import API +from .queries import MapQuery