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>
This commit is contained in:
Jose Nelson
2026-03-14 00:53:47 +03:00
committed by GitHub
co-authored by Pamela Cano pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Maxim Smolskiy
parent 7e4b60b05c
commit 68473afc4b
+28
View File
@@ -32,6 +32,26 @@ def lamberts_ellipsoidal_distance(
Returns:
geographical distance between two points in metres
>>> lamberts_ellipsoidal_distance(100, 0, 0, 0)
Traceback (most recent call last):
...
ValueError: Latitude must be between -90 and 90 degrees
>>> lamberts_ellipsoidal_distance(0, 0, -100, 0)
Traceback (most recent call last):
...
ValueError: Latitude must be between -90 and 90 degrees
>>> lamberts_ellipsoidal_distance(0, 200, 0, 0)
Traceback (most recent call last):
...
ValueError: Longitude must be between -180 and 180 degrees
>>> lamberts_ellipsoidal_distance(0, 0, 0, -200)
Traceback (most recent call last):
...
ValueError: Longitude must be between -180 and 180 degrees
>>> from collections import namedtuple
>>> point_2d = namedtuple("point_2d", "lat lon")
>>> SAN_FRANCISCO = point_2d(37.774856, -122.424227)
@@ -46,6 +66,14 @@ def lamberts_ellipsoidal_distance(
'9,737,326 meters'
"""
# Validate latitude values
if not -90 <= lat1 <= 90 or not -90 <= lat2 <= 90:
raise ValueError("Latitude must be between -90 and 90 degrees")
# Validate longitude values
if not -180 <= lon1 <= 180 or not -180 <= lon2 <= 180:
raise ValueError("Longitude must be between -180 and 180 degrees")
# CONSTANTS per WGS84 https://en.wikipedia.org/wiki/World_Geodetic_System
# Distance in metres(m)
# Equation Parameters