From 33eb043a6a175abd0adf56b1337c760102aae448 Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sat, 20 Feb 2021 07:17:06 +0100 Subject: [PATCH 1/2] Adds photon's bbox param --- geopy/geocoders/photon.py | 14 +++++++++++++- test/geocoders/photon.py | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/geopy/geocoders/photon.py b/geopy/geocoders/photon.py index 79a5bb92f..35c31aa04 100644 --- a/geopy/geocoders/photon.py +++ b/geopy/geocoders/photon.py @@ -82,7 +82,8 @@ def geocode( location_bias=None, language=False, limit=None, - osm_tag=None + osm_tag=None, + bbox=None ): """ Return a location point by address. @@ -109,6 +110,12 @@ def geocode( filters are required as ``['key:!val', '!key', ':!value']``. :type osm_tag: str or list or set + :param bbox: The bounding box of the viewport within which + to bias geocode results more prominently. + Example: ``[Point(22, 180), Point(-22, -180)]``. + :type bbox: list or tuple of 2 items of :class:`geopy.point.Point` or + ``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``. + :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if ``exactly_one=False``. @@ -130,6 +137,11 @@ def geocode( except ValueError: raise ValueError(("Location bias must be a" " coordinate pair or Point")) + + if bbox: + params['bbox'] = self._format_bounding_box( + bbox, "%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)s") + if osm_tag: if isinstance(osm_tag, str): params['osm_tag'] = [osm_tag] diff --git a/test/geocoders/photon.py b/test/geocoders/photon.py index 258839592..e24a6c0d8 100644 --- a/test/geocoders/photon.py +++ b/test/geocoders/photon.py @@ -35,6 +35,12 @@ async def test_osm_tag(self): {"latitude": 44.3862491, "longitude": -88.290994, "delta": 2.0}, ) + async def test_bbox(self): + await self.geocode_run( + {"query": "Marbach", "bbox": [(50.16, 10.67),(50.17, 10.68)]}, + {"latitude": 50.1667628, "longitude": 10.6786321, "delta": 2.0}, + ) + async def test_unicode_name(self): await self.geocode_run( {"query": "\u6545\u5bab"}, From 1a33ce919295fb92617a002d982e0f58eb2b772b Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sat, 20 Feb 2021 07:25:35 +0100 Subject: [PATCH 2/2] Fix lint issues --- geopy/geocoders/photon.py | 2 +- test/geocoders/photon.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geopy/geocoders/photon.py b/geopy/geocoders/photon.py index 35c31aa04..a27b7f0a1 100644 --- a/geopy/geocoders/photon.py +++ b/geopy/geocoders/photon.py @@ -141,7 +141,7 @@ def geocode( if bbox: params['bbox'] = self._format_bounding_box( bbox, "%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)s") - + if osm_tag: if isinstance(osm_tag, str): params['osm_tag'] = [osm_tag] diff --git a/test/geocoders/photon.py b/test/geocoders/photon.py index e24a6c0d8..786eecbc9 100644 --- a/test/geocoders/photon.py +++ b/test/geocoders/photon.py @@ -37,7 +37,7 @@ async def test_osm_tag(self): async def test_bbox(self): await self.geocode_run( - {"query": "Marbach", "bbox": [(50.16, 10.67),(50.17, 10.68)]}, + {"query": "Marbach", "bbox": [(50.16, 10.67), (50.17, 10.68)]}, {"latitude": 50.1667628, "longitude": 10.6786321, "delta": 2.0}, )