Skip to content

Commit 1230d67

Browse files
committed
Merge branch 'main' of github.com:mapillary/mapillary-python-sdk into Rubix982/Docusaurus-Release
Merge changes from main
2 parents ecc3e59 + 49123e4 commit 1230d67

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/mapillary/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Local
2121
from mapillary.models.geojson import GeoJSON
2222
from mapillary.utils.auth import auth, set_token
23-
23+
from mapillary.utils.verify import international_dateline_check, bbox_validity_check
2424
# Exception classes
2525
from mapillary.models.exceptions import InvalidOptionError
2626

src/mapillary/models/exceptions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616
# Package imports
1717
import typing
1818

19+
class InvalidBBoxError(MapillaryException):
20+
"""
21+
Raised when an invalid coordinates for bounding box are entered
22+
to access Mapillary's API.
23+
24+
:var message: The error message returned
25+
:type message: str
26+
"""
27+
def __init__(self, message: str):
28+
self.message = message
29+
30+
def __str__(self):
31+
return (
32+
f'InvalidBBoxError: "{self.message}" '
33+
)
34+
35+
def __repr__(self):
36+
return (
37+
f'InvalidBBoxError: = "{self.message}" '
38+
)
1939

2040
class MapillaryException(Exception):
2141
"""Base class for exceptions in this module"""

src/mapillary/utils/verify.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,45 @@
1616
"""
1717

1818
# Local Imports
19-
from mapillary.models.exceptions import InvalidKwargError, InvalidOptionError
19+
from mapillary.models.exceptions import InvalidBBoxError, InvalidKwargError, InvalidOptionError
2020
from mapillary.config.api.entities import Entities
2121
from mapillary.models.client import Client
2222

2323
# Package Imports
2424
import requests
2525
import re
2626

27+
def international_dateline_check(bbox):
28+
if bbox['west']>0 and bbox['east']<0:
29+
return True
30+
return False
31+
32+
def bbox_validity_check(bbox):
33+
# longitude check
34+
if bbox['west'] < 180 or bbox['east'] > 180:
35+
raise InvalidBBoxError(message="Input values exceed their permitted limits")
36+
# lattitude check
37+
elif bbox['north'] > 90 or bbox['south'] < 90:
38+
raise InvalidBBoxError(message="Input values exceed their permitted limits")
39+
# longitude validity check
40+
elif bbox['west']>bbox['east'] :
41+
# extra check for international dateline
42+
# it could either be an error or cross an internaitonal dateline
43+
# hence if it is passing the dateline, return True
44+
if international_dateline_check(bbox):
45+
new_east = bbox['east'] + 360
46+
bbox['east'] = new_east
47+
return bbox
48+
raise InvalidBBoxError(message="Invalid values")
49+
# lattitude validitiy check
50+
elif bbox['north']<bbox['south']:
51+
raise InvalidBBoxError(message="Invalid values")
52+
elif bbox['north']==bbox['south'] and bbox['west']==bbox['east']:
53+
# checking for equal values to avoid flat box
54+
raise InvalidBBoxError(message="Invalid values")
2755

56+
return True
57+
2858
def kwarg_check(kwargs: dict, options: list, callback: str) -> bool:
2959
"""
3060
Checks for keyword arguments amongst the kwarg argument to fall into the options list

0 commit comments

Comments
 (0)