|
30 | 30 | import mapillary.controller.detection as detection |
31 | 31 | import mapillary.controller.save as save |
32 | 32 |
|
| 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 |
33 | 63 |
|
34 | 64 | def set_access_token(token: str): |
35 | 65 | """A function allowing the user to set an access |
@@ -371,10 +401,13 @@ def images_in_bbox(bbox: dict, **filters) -> str: |
371 | 401 | ... organization_id='ORG_ID' |
372 | 402 | ... ) |
373 | 403 | """ |
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 |
378 | 411 |
|
379 | 412 |
|
380 | 413 | @auth() |
@@ -420,10 +453,13 @@ def sequences_in_bbox(bbox: dict, **filters) -> str: |
420 | 453 | ... org_id='ORG_ID' |
421 | 454 | ... ) |
422 | 455 | """ |
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 |
427 | 463 |
|
428 | 464 |
|
429 | 465 | @auth() |
@@ -523,10 +559,14 @@ def traffic_signs_in_bbox( |
523 | 559 | ... existed_before='YYYY-MM-DD HH:MM:SS' |
524 | 560 | ... ) |
525 | 561 | """ |
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 | + |
530 | 570 |
|
531 | 571 |
|
532 | 572 | @auth() |
|
0 commit comments