Skip to content

Commit d328bde

Browse files
committed
reviews for check_bbox_validity
1 parent fa6ac90 commit d328bde

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

src/mapillary/interface.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@
3030
import mapillary.controller.detection as detection
3131
import mapillary.controller.save as save
3232

33+
def international_dateline(bbox):
34+
if bbox['west']>0 and bbox['east']<0:
35+
return True
36+
return False
37+
38+
def check_bbox_validity(bbox):
39+
# longitude check
40+
if bbox['west'] < 180 or bbox['east'] > 180:
41+
return False
42+
# lattitude check
43+
elif bbox['north'] > 90 or bbox['south'] < 90:
44+
return False
45+
# longitude validity check
46+
elif bbox['west']>bbox['east'] :
47+
# extra check for international dateline
48+
# it could either be an error or cross an internaitonal dateline
49+
# hence if it is passing the dateline, return True
50+
if international_dateline(bbox):
51+
new_east = bbox['east'] + 360
52+
bbox['east'] = new_east
53+
return bbox
54+
return False
55+
# lattitude validitiy check
56+
elif bbox['north']<bbox['south']:
57+
return False
58+
elif bbox['north']==bbox['south'] and bbox['west']==bbox['east']:
59+
# checking for equal values to avoid flat box
60+
return False
61+
else:
62+
return True
3363

3464
def set_access_token(token: str):
3565
"""A function allowing the user to set an access
@@ -371,10 +401,13 @@ def images_in_bbox(bbox: dict, **filters) -> str:
371401
... organization_id='ORG_ID'
372402
... )
373403
"""
374-
375-
return image.get_images_in_bbox_controller(
376-
bbox=bbox, layer="image", zoom=14, filters=filters
377-
)
404+
if check_bbox_validity(bbox):
405+
return image.get_images_in_bbox_controller(
406+
bbox=bbox, layer="image", zoom=14, filters=filters
407+
)
408+
else:
409+
print("Please enter the correct bounding box values")
410+
return
378411

379412

380413
@auth()
@@ -420,10 +453,13 @@ def sequences_in_bbox(bbox: dict, **filters) -> str:
420453
... org_id='ORG_ID'
421454
... )
422455
"""
423-
424-
return image.get_images_in_bbox_controller(
425-
bbox=bbox, layer="sequence", zoom=14, filters=filters
426-
)
456+
if check_bbox_validity(bbox):
457+
return image.get_images_in_bbox_controller(
458+
bbox=bbox, layer="sequence", zoom=14, filters=filters
459+
)
460+
else:
461+
print("Please enter the correct bounding box values")
462+
return
427463

428464

429465
@auth()
@@ -523,10 +559,14 @@ def traffic_signs_in_bbox(
523559
... existed_before='YYYY-MM-DD HH:MM:SS'
524560
... )
525561
"""
526-
527-
return feature.get_map_features_in_bbox_controller(
528-
bbox=bbox, filters=filters, filter_values=filter_values, layer="traffic_signs"
529-
)
562+
if check_bbox_validity(bbox):
563+
return feature.get_map_features_in_bbox_controller(
564+
bbox=bbox, filters=filters, filter_values=filter_values, layer="traffic_signs"
565+
)
566+
else:
567+
print("Please enter the correct bounding box values")
568+
return
569+
530570

531571

532572
@auth()

0 commit comments

Comments
 (0)