Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ 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
>>> map_query = overpass.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).
Expand Down
3 changes: 2 additions & 1 deletion overpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
__version__ = '0.0.1'
__license__ = 'Apache 2.0'

from .api import API
from .api import API
from .queries import MapQuery
14 changes: 9 additions & 5 deletions overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions overpass/queries.py
Original file line number Diff line number Diff line change
@@ -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)