diff --git a/overpass/api.py b/overpass/api.py index a7790ad..23977c2 100644 --- a/overpass/api.py +++ b/overpass/api.py @@ -43,7 +43,7 @@ class API(object): _proxies = None _QUERY_TEMPLATE = "[out:{out}];{query}out {verbosity};" - _GEOJSON_QUERY_TEMPLATE = "[out:json];{query}out {verbosity};" + _GEOJSON_QUERY_TEMPLATE = "[out:json]{bbox};{query}out {verbosity};" def __init__(self, *args, **kwargs): self.endpoint = kwargs.get("endpoint", self._endpoint) @@ -70,7 +70,7 @@ class API(object): requests_log.setLevel(logging.DEBUG) requests_log.propagate = True - def get(self, query, responseformat="geojson", verbosity="body", build=True): + def get(self, query, responseformat="geojson", verbosity="body", build=True, bbox=""): """Pass in an Overpass query in Overpass QL. :param query: the Overpass QL query to send to the endpoint @@ -81,11 +81,13 @@ class API(object): "body geom qt" :param build: boolean to indicate whether to build the overpass query from a template (True) or allow the programmer to specify full query manually (False) + :param bbox: bounding box string, defaults to ""; if supplied, value should include + square brackets, e.g. "[bbox:38.843,-77.154,39.033,-76.964]" """ # Construct full Overpass query if build: full_query = self._construct_ql_query( - query, responseformat=responseformat, verbosity=verbosity + query, responseformat=responseformat, verbosity=verbosity, bbox=bbox ) else: full_query = query @@ -137,14 +139,14 @@ class API(object): Get = get Search = search - def _construct_ql_query(self, userquery, responseformat, verbosity): + def _construct_ql_query(self, userquery, responseformat, verbosity, bbox): raw_query = str(userquery).rstrip() if not raw_query.endswith(";"): raw_query += ";" if responseformat == "geojson": template = self._GEOJSON_QUERY_TEMPLATE - complete_query = template.format(query=raw_query, verbosity=verbosity) + complete_query = template.format(bbox=bbox, query=raw_query, verbosity=verbosity) else: template = self._QUERY_TEMPLATE complete_query = template.format(