Skip to content

Commit 68473af

Browse files
galleazzijuniorsoftwareenginerPamela Canopre-commit-ci[bot]MaximSmolskiy
authored
Add latitude and longitude validation to lamberts_ellipsoidal_distance (#14373)
* Add latitude and longitude validation with doctests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update lamberts_ellipsoidal_distance.py --------- Co-authored-by: Pamela Cano <pamelacano@MacBook-Pro-de-Pamela.local> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 7e4b60b commit 68473af

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

geodesy/lamberts_ellipsoidal_distance.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ def lamberts_ellipsoidal_distance(
3232
Returns:
3333
geographical distance between two points in metres
3434
35+
>>> lamberts_ellipsoidal_distance(100, 0, 0, 0)
36+
Traceback (most recent call last):
37+
...
38+
ValueError: Latitude must be between -90 and 90 degrees
39+
40+
>>> lamberts_ellipsoidal_distance(0, 0, -100, 0)
41+
Traceback (most recent call last):
42+
...
43+
ValueError: Latitude must be between -90 and 90 degrees
44+
45+
>>> lamberts_ellipsoidal_distance(0, 200, 0, 0)
46+
Traceback (most recent call last):
47+
...
48+
ValueError: Longitude must be between -180 and 180 degrees
49+
50+
>>> lamberts_ellipsoidal_distance(0, 0, 0, -200)
51+
Traceback (most recent call last):
52+
...
53+
ValueError: Longitude must be between -180 and 180 degrees
54+
3555
>>> from collections import namedtuple
3656
>>> point_2d = namedtuple("point_2d", "lat lon")
3757
>>> SAN_FRANCISCO = point_2d(37.774856, -122.424227)
@@ -46,6 +66,14 @@ def lamberts_ellipsoidal_distance(
4666
'9,737,326 meters'
4767
"""
4868

69+
# Validate latitude values
70+
if not -90 <= lat1 <= 90 or not -90 <= lat2 <= 90:
71+
raise ValueError("Latitude must be between -90 and 90 degrees")
72+
73+
# Validate longitude values
74+
if not -180 <= lon1 <= 180 or not -180 <= lon2 <= 180:
75+
raise ValueError("Longitude must be between -180 and 180 degrees")
76+
4977
# CONSTANTS per WGS84 https://en.wikipedia.org/wiki/World_Geodetic_System
5078
# Distance in metres(m)
5179
# Equation Parameters

0 commit comments

Comments
 (0)