[英]Position between two (lat,long)-coordinates in Python
I need to do the following in Python.我需要在 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.
给定两个位置 (lat1,lon1) 和 (lat2,lon2),我需要得到点 (lat0,lon0),它位于分数 alpha 的给定两点之间的路径上。 Ie 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, eg I use geopy.distance to compute distances between points.
即 alpha = 0.5 是点之间的中点,但我需要为任何 0 <=alpha <= 1 计算它。如果可能,我想使用已经定义的包,例如我使用 geopy.distance 来计算点之间的距离. Thanks!
谢谢!
Take a look at the "Intermediate Point" section on this page.查看此页面上的“中间点”部分。
It describes the formula mathematically:它在数学上描述了公式:
a = sin((1−f)⋅δ) / sin δ
a = sin((1−f)⋅δ) / sin δ
b = sin(f⋅δ) / sin δb = sin(f⋅δ) / sin δ
x = a ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2x = a ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2
y = a ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2y = a ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2
z = a ⋅ sin φ1 + b ⋅ sin φ2z = a ⋅ sin φ1 + b ⋅ sin φ2
φi = atan2(z, √x² + y²)φi = atan2(z, √x² + y²)
λi = atan2(y, x)λi = atan2(y, x)
Which translates into Python quite easily, and is translated into JavaScript on the page.这很容易转换为 Python,并在页面上转换为 JavaScript。
I was unable to find a way to do this using GeoPy.我无法找到使用 GeoPy 执行此操作的方法。
here there is a nice library: great-circle-calculator这里有一个不错的库: great-circle-calculator
The function you may look for is:您可能会寻找的功能是:
intermediate_point(p1, p2, fraction=0.5)
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.