X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/9f6f12cfeb5ab51d2604b459f668c21530d7ad26..5360384b7024fb2a1f84fee55511beef41c3fd46:/nominatim/api/types.py diff --git a/nominatim/api/types.py b/nominatim/api/types.py index 60495dd0..a2a265c0 100644 --- a/nominatim/api/types.py +++ b/nominatim/api/types.py @@ -16,8 +16,6 @@ import math from struct import unpack from binascii import unhexlify -import sqlalchemy as sa - from nominatim.errors import UsageError # pylint: disable=no-member,too-many-boolean-expressions,too-many-instance-attributes @@ -192,7 +190,8 @@ class Bbox: """ Return the WKT representation of the Bbox. This is a simple polygon with four points. """ - return 'POLYGON(({0} {1},{0} {3},{2} {3},{2} {1},{0} {1}))'.format(*self.coords) + return 'POLYGON(({0} {1},{0} {3},{2} {3},{2} {1},{0} {1}))'\ + .format(*self.coords) # pylint: disable=consider-using-f-string @staticmethod @@ -248,9 +247,10 @@ class Bbox: except ValueError as exc: raise UsageError('Bounding box parameter needs to be numbers.') from exc - if x1 < -180.0 or x1 > 180.0 or y1 < -90.0 or y1 > 90.0 \ - or x2 < -180.0 or x2 > 180.0 or y2 < -90.0 or y2 > 90.0: - raise UsageError('Bounding box coordinates invalid.') + x1 = min(180, max(-180, x1)) + x2 = min(180, max(-180, x2)) + y1 = min(90, max(-90, y1)) + y2 = min(90, max(-90, y2)) if x1 == x2 or y1 == y2: raise UsageError('Bounding box with invalid parameters.') @@ -445,6 +445,7 @@ class SearchDetails(LookupDetails): """ Restrict search to places with one of the given class/type categories. An empty list (the default) will disable this filter. """ + viewbox_x2: Optional[Bbox] = None def __post_init__(self) -> None: if self.viewbox is not None: @@ -452,8 +453,6 @@ class SearchDetails(LookupDetails): yext = (self.viewbox.maxlat - self.viewbox.minlat)/2 self.viewbox_x2 = Bbox(self.viewbox.minlon - xext, self.viewbox.minlat - yext, self.viewbox.maxlon + xext, self.viewbox.maxlat + yext) - else: - self.viewbox_x2 = None def restrict_min_max_rank(self, new_min: int, new_max: int) -> None: