import math
x = 0.0
y = 0.0
z = 0.0
for i, coord in coords_df.iterrows():
latitude = math.radians(coord.latitude)
longitude = math.radians(coord.longitude)
x += math.cos(latitude) * math.cos(longitude)
y += math.cos(latitude) * math.sin(longitude)
z += math.sin(latitude)
total = len(coords_df)
x = x / total
y = y / total
z = z / total
central_longitude = math.atan2(y, x)
central_square_root = math.sqrt(x * x + y * y)
central_latitude = math.atan2(z, central_square_root)
mean_location = {
'latitude': math.degrees(central_latitude),
'longitude': math.degrees(central_longitude)
}
在
comments
之后,我从HERE接收并评论使用
close to each other
坐标,可以将地球视为局部平坦,只需像平面坐标一样找到质心。然后你只需要取纬度的平均值和经度的average
就可以找到centroid
的latitude
和longitude
。基于:https://gist.github.com/tlhunter/0ea604b77775b3e7d7d25ea0f70a23eb
假设您有一个带有纬度和经度列的pandas数据框,下一个代码将返回一个带有平均坐标的字典。
考虑到您使用的是有符号度数格式(more),简单的纬度和经度平均值会因为这条线的经度值的不连续性(在-180到180之间的突然跳跃)而给反经度附近的小区域(即+或-180度经度)带来问题。
假设两个位置的经度是-179和179,它们的平均值是0,这是错误的。
相关问题 更多 >
编程相关推荐