1
votes

I need to do the following in Python. Given two positios (lat1,lon1) and (lat2,lon2), I need to get the point (lat0,lon0) which lies on the path between the given two points at fraction alpha. I.e. alpha = 0.5 is the midpoint between the points, but I need to compute it for any 0 <=alpha <= 1. I would like to use a package already defined if possible, e.g. I use geopy.distance to compute distances between points. Thanks!

3

3 Answers

0
votes

Take a look at the "Intermediate Point" section on this page.

It describes the formula mathematically:

a = sin((1−f)⋅δ) / sin δ
b = sin(f⋅δ) / sin δ
x = a ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2
y = a ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2
z = a ⋅ sin φ1 + b ⋅ sin φ2
φi = atan2(z, √x² + y²)
λi = atan2(y, x)

Which translates into Python quite easily, and is translated into JavaScript on the page.

I was unable to find a way to do this using GeoPy.

0
votes

here there is a nice library: great-circle-calculator

The function you may look for is:

intermediate_point(p1, p2, fraction=0.5)
-1
votes
def find_point(a,b,alpha = 0.5):
    assert(0<=alpha<=1)
    new_a = ((1-alpha) * a[0], (1-alpha)*a[1])
    new_b = ((alpha) * b[0], alpha*b[1])
    return ((new_a[0]+new_b[0]), (new_a[1]+new_b[1]))

test-

>>>find_point((1,1),(2,2))
(1.5, 1.5)