gpt4 book ai didi

math - 计算多个纬度/经度坐标对的中心点

转载 作者:行者123 更新时间:2023-12-03 04:28:30 25 4
gpt4 key购买 nike

给定一组纬度和经度点,如何计算该组中心点(也称为将 View 集中在所有点上的点)的纬度和经度?

编辑:我使用过的Python解决方案:

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)

最佳答案

谢谢!这是 OP 使用度的解决方案的 C# 版本。它利用System.Device.Location.GeoCoordinate

    public static GeoCoordinate GetCentralGeoCoordinate(
IList<GeoCoordinate> geoCoordinates)
{
if (geoCoordinates.Count == 1)
{
return geoCoordinates.Single();
}

double x = 0;
double y = 0;
double z = 0;

foreach (var geoCoordinate in geoCoordinates)
{
var latitude = geoCoordinate.Latitude * Math.PI / 180;
var longitude = geoCoordinate.Longitude * Math.PI / 180;

x += Math.Cos(latitude) * Math.Cos(longitude);
y += Math.Cos(latitude) * Math.Sin(longitude);
z += Math.Sin(latitude);
}

var total = geoCoordinates.Count;

x = x / total;
y = y / total;
z = z / total;

var centralLongitude = Math.Atan2(y, x);
var centralSquareRoot = Math.Sqrt(x * x + y * y);
var centralLatitude = Math.Atan2(z, centralSquareRoot);

return new GeoCoordinate(centralLatitude * 180 / Math.PI, centralLongitude * 180 / Math.PI);
}

关于math - 计算多个纬度/经度坐标对的中心点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6671183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com