计算多个经纬度坐标对的中心点 [英] Calculate the center point of multiple latitude/longitude coordinate pairs

查看:28
本文介绍了计算多个经纬度坐标对的中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一组纬度和经度点,我如何计算该组中心点的纬度和经度(也就是将视图集中在所有点上的点)?

Given a set of latitude and longitude points, how can I calculate the latitude and longitude of the center point of that set (aka a point that would center a view on all points)?

我使用过的 Python 解决方案:

Python solution I've used:

Convert lat/lon (must be in radians) to Cartesian coordinates for each location.
X = cos(lat) * cos(lon)
Y = cos(lat) * sin(lon)
Z = sin(lat)

Compute average x, y and z coordinates.
x = (x1 + x2 + ... + xn) / n
y = (y1 + y2 + ... + yn) / n
z = (z1 + z2 + ... + zn) / n

Convert average x, y, z coordinate to latitude and longitude.
Lon = atan2(y, x)
Hyp = sqrt(x * x + y * y)
Lat = atan2(z, hyp)

推荐答案

当它们从 359' 折回到 0' 时,将它们平均化的简单方法会产生带有角度的奇怪边缘情况.

The simple approach of just averaging them has weird edge cases with angles when they wrap from 359' back to 0'.

A 更早关于 SO 的问题是关于找到一组罗盘角度的平均值.

A much earlier question on SO asked about finding the average of a set of compass angles.

对球坐标推荐的方法的扩展是:

An expansion of the approach recommended there for spherical coordinates would be:

  • 将每个纬度/经度对转换为单位长度的 3D 向量.
  • 对每个向量求和
  • 对结果向量进行归一化
  • 转换回球坐标

这篇关于计算多个经纬度坐标对的中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆