计算多个点的中心点坐标

400Km以上时计算方式:

/// <summary>  
/// 根据输入的地点坐标计算中心点  
/// </summary>  
/// <param name="geoCoordinateList"></param>  
/// <returns></returns>  
public GeoCoordinate GetCenterPointFromListOfCoordinates(List<GeoCoordinate> geoCoordinateList)  
{  
    int total = geoCoordinateList.Count;  
    double X = 0, Y = 0, Z = 0;  
    foreach (GeoCoordinate g in geoCoordinateList)  
    {  
        double lat, lon, x, y, z;  
        lat = g.Latitude * Math.PI / 180;  
        lon = g.Longitude * Math.PI / 180;  
        x = Math.Cos(lat) * Math.Cos(lon);  
        y = Math.Cos(lat) * Math.Sin(lon);  
        z = Math.Sin(lat);  
        X += x;  
        Y += y;  
        Z += z;  
    }  
    X = X / total;  
    Y = Y / total;  
    Z = Z / total;  
    double Lon = Math.Atan2(Y, X);  
    double Hyp = Math.Sqrt(X * X + Y * Y);  
    double Lat = Math.Atan2(Z, Hyp);  
    return new GeoCoordinate(Lat * 180 / Math.PI, Lon * 180 / Math.PI);  
}  


400Km以下时算法:

/// <summary>  
/// 根据输入的地点坐标计算中心点(适用于400km以下的场合)  
/// </summary>  
/// <param name="geoCoordinateList"></param>  
/// <returns></returns>  
public GeoCoordinate GetCenterPointFromListOfCoordinates(List<GeoCoordinate> geoCoordinateList)  
{  
    //以下为简化方法(400km以内)  
    int total = geoCoordinateList.Count;  
    double lat = 0, lon = 0;  
    foreach (GeoCoordinate g in geoCoordinateList)  
    {  
        lat += g.Latitude * Math.PI / 180;  
        lon += g.Longitude * Math.PI / 180;  
    }  
    lat /= total;  
    lon /= total;  
    return new GeoCoordinate(lat * 180 / Math.PI, lon * 180 / Math.PI);  
}  

原文地址:http://blog.csdn.net/yl2isoft/article/details/16368397

在以下页面包含有多种实现,大家可以参考。

http://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairshttp://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs

 详细的算法说明,可以参考。

http://www.geomidpoint.com/calculation.html




猜你喜欢

转载自blog.csdn.net/u012604299/article/details/78326371