-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Explicit types -Haversine distance -Functions to re-implement
- Loading branch information
1 parent
f869177
commit 550d5dd
Showing
7 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .distance import * | ||
from .projections import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import math as m | ||
|
||
# latitude/longitude in GPX files is always in WGS84 datum | ||
# WGS84 defined the Earth semi-major axis with 6378.137 km | ||
# https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84 | ||
EARTH_RADIUS = 6378.137 * 1000 | ||
|
||
def haversine_distance(latitude_1: float, longitude_1: float, latitude_2: float, longitude_2: float) -> float: | ||
""" | ||
Compute Haversine distance between to points. | ||
https://en.wikipedia.org/wiki/Haversine_formula | ||
Args: | ||
latitude_1 (float): Latitude of the first point. | ||
longitude_1 (float): Longitude of the first point. | ||
latitude_2 (float): Latitude of the second point. | ||
longitude_2 (float): Longitude of the second point. | ||
Returns: | ||
float: Haversine distance between the points. | ||
""" | ||
# Delta and conversion to radians | ||
delta_lat = m.radians(latitude_1 - latitude_2) | ||
delta_long = m.radians(longitude_1 - longitude_2) | ||
|
||
sin_1 = m.sin(delta_lat/2) | ||
sin_2 = m.sin(delta_long/2) | ||
a = m.sqrt(sin_1 * sin_1 + m.cos(latitude_1) * m.cos(latitude_2) * sin_2 * sin_2) | ||
d = 2 * EARTH_RADIUS * m.asin(a) | ||
|
||
return d | ||
|
Binary file not shown.