Skip to content

Distances

add_distance_to_lat_lon(latitude, longitude, x, y)

Given a latitude and a longitude (in degrees), and two distances (x, y) in km, adds those distances to lat and lon

Parameters:

Name Type Description Default
latitude
required
longitude
required
x
required
y
required
Source code in june/utils/distances.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def add_distance_to_lat_lon(latitude, longitude, x, y):
    """Given a latitude and a longitude (in degrees), and two distances (x, y) in km, adds those distances
    to lat and lon

    Args:
        latitude: 
        longitude: 
        x: 
        y: 

    """
    lat2 = latitude + 180 * y / (earth_radius * np.pi)
    lon2 = longitude + 180 * x / (earth_radius * np.pi * np.cos(latitude))
    return lat2, lon2

haversine_distance(origin, destination)

Taken from https://gist.github.com/rochacbruno/2883505

Author: Wayne Dyck

Parameters:

Name Type Description Default
origin, destination tuple[float, float]

Points to calculate the distance between. Takes into account the curvature of the earth.

required
Source code in june/utils/distances.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def haversine_distance(origin, destination):
    """Taken from https://gist.github.com/rochacbruno/2883505
    # Author: Wayne Dyck

    Args:
        origin, destination (tuple[float,float]):
            Points to calculate the distance between. Takes into account the curvature of the earth. 

    """
    lat1, lon1 = origin
    lat2, lon2 = destination

    dlat = math.radians(lat2 - lat1)
    dlon = math.radians(lon2 - lon1)
    a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(
        math.radians(lat1)
    ) * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    d = earth_radius * c
    return d