C++:高斯坐标,大地坐标转经纬度

实现CGCS2000大地坐标系XY值转化为对应经纬度信息,
注意输入的XY值与给定的值相反,则参数X为已知的Y,参数Y为已知的X。 得出的结果为 [纬度,经度],不要应用错误。
L0参数为中央子午线的经线值,应用方法前需要确定L0的值,否则得出的值会有很大的偏差。

void xylb(double l0, double x, double y, double *l, double *b)
{
    double bf,vf,nf,ynf,tf,yf2,hbf;
    double sa,sb,se2,sep2,mf;
    double w1,w2,w,w3,w4;
    double pi = 3.1415926;
    x = x/1000000.0;
    y = y - 500000.0;
    bf = 9.04353692458*x-0.00001007623*pow(x,2.0)-0.00074438304*pow(x,3.0)-0.00000463064*pow(x,4.0)+0.00000505846*pow(x,5.0)-0.00000016754*pow(x,6.0);
    hbf = bf * pi/ 180.0;
    //北京
//    sa = 6378245.0;
//    sb = 6356863.019;
    //西安
//    sa = 6378140;
//    sb = 6356755.28820;
    //高斯
    sa = 6378137.0; //长半轴 m
    sb = 6356752.31414; //短半轴 m

    se2 = 0.006693421623;
    sep2 = 0.006738525415;
    w1 = sin(hbf);
    w2 = 1.0 - se2 * pow(w1,(double)2);
    w = sqrt(w2);
    mf = sa*(1.0-se2)/pow(w,(double)3);
    w3 = cos(hbf);
    w4 = pow(sa,(double)2)*pow(w3,(double)2) + pow(sb,(double)2)*pow(w1,(double)2);
    nf = pow(sa,(double)2) / sqrt(w4);
    ynf = y/nf;
    vf = nf/mf;
    tf = tan(hbf);
    yf2 = sep2 * pow(w3, (double)2);
    *b = bf - 1.0/2.0 * vf * tf * (pow(ynf,(double)2)-1.0/12.0*(5.0+3.0*pow(tf,(double)2)+yf2-9.0*yf2*pow(tf,(double)2))*pow(ynf,(double)4))*180.0/pi;
    *l = 1.0/w3*ynf*(1.0-1.0/6.0*(1.0+2.0*pow(tf,(double)2)+yf2)*pow(ynf,(double)2)+1.0/120.0*(5.0+28.0*pow(tf,(double)2)+24.0*pow(tf,(double)2)+6.0*yf2+8.0*yf2*pow(tf,(double)2))*pow(ynf,(double)4))*180.0/pi;
    *l = l0 + *l;
}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是C++实现高斯坐标经纬度坐标的函数: ```c++ #include <cmath> // 定义常量 const double PI = 3.14159265358979323846; const double a = 6378137.0; // 长半轴 const double b = 6356752.3142; // 短半轴 const double f = 1.0 / 298.257223563; // 扁率 const double e2 = f * (2 - f); // 第一偏心率的平方 const double ee2 = e2 / (1 - e2); // 第二偏心率的平方 // 高斯投影正算 void GaussForward(double B, double L, double &X, double &Y, double L0, double K0) { double L1 = L - L0; double l = L1 * PI / 180; double b = B * PI / 180; double N = a / sqrt(1 - e2 * sin(b) * sin(b)); double t = tan(b); double g = sqrt(ee2) * cos(b); double m = cos(b) * l; double s = sin(b); double n = sqrt(ee2) * s; double t1 = t * t; double g2 = g * g; double N2 = N * N; double cos3 = cos(b) * cos(b) * cos(b); double sin2 = sin(b) * sin(b); double x = K0 * N * (m + (1 - t1 + g2) * m * m * m / 6.0 + (5 - 18 * t1 + t1 * t1 + 72 * g2 - 58 * ee2) * m * m * m * m * m / 120.0); double y = K0 * (N * t + N * (9 * ee2 + 4 * g2 - 12) * t * t * t / 24.0 + N * (61 - 58 * t1 + t1 * t1 + 600 * g2 - 330 * ee2) * t * t * t * t * t / 720.0); X = x + 500000; Y = y; } // 高斯投影反算 void GaussInverse(double X, double Y, double &B, double &L, double L0, double K0) { Y = Y / K0; double x = X - 500000; double e1 = (1 - sqrt(1 - e2)) / (1 + sqrt(1 - e2)); double xx = x / (a * K0); double m = xx / cos(B); double m2 = m * m; double m3 = m2 * m; double m4 = m3 * m; double m5 = m4 * m; double n = (e2 * cos(B) * cos(B)) / (1 - e2); double n2 = n * n; double t = tan(B); double t2 = t * t; double t4 = t2 * t2; double t6 = t4 * t2; double cos3 = cos(B) * cos(B) * cos(B); double cos5 = cos3 * cos(B) * cos(B); double eta = ee2 * cos(B) * cos(B); double eta2 = eta * eta; double eta3 = eta2 * eta; double eta4 = eta3 * eta; B = B - t * xx * xx / (2 * a * a * N) + t * (5 + 3 * t2 + n - 9 * eta) * xx * xx * xx * xx / (24 * a * a * a * a * N * N * N) - t * (61 + 90 * t2 + 45 * t4) * xx * xx * xx * xx * xx * xx / (720 * a * a * a * a * a * a * N * N * N * N * N) + t * xx * xx * xx * xx * xx * xx * (1385 + 3633 * t2 + 4095 * t4 + 1575 * t6) / (40320 * a * a * a * a * a * a * a * a * N * N * N * N * N * N); L = L0 + m - (1 + 2 * t2 + n) * m3 / 6 + (5 - 2 * n + 28 * t2 - 3 * n2 + 8 * eta + 24 * t4) * m5 / 120; B = B * 180 / PI; L = L * 180 / PI; } ``` 其中,高斯投影正算函数`GaussForward`的参数为输入的经度`L`和纬度`B`,输出的高斯坐标`X`和`Y`,以及中央子午线经度`L0`和比例因子`K0`;高斯投影反算函数`GaussInverse`的参数为输入的高斯坐标`X`和`Y`,输出的经度`L`和纬度`B`,以及中央子午线经度`L0`和比例因子`K0`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值