IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]GPS坐标转笛卡尔坐标

    qp120291570发表于 2014-11-28 16:12:57
    love 0

    提要

    我们知道GPS坐标是由经度,纬度,海拔组成,精度和纬度都是角度,海报是高度。

    在进行基于地理的搜索的时候,常用到KDTree,在构建在KDTree的时候,不能直接用GPS的坐标,要将GPS坐标转换成笛卡尔坐标才能用于构建KDTree。下面就是相关的转换算法。

    注:GPS信息由几种标准,这里的采用的是google map的经纬度信息。


    js实现

    geodecy.js

    /*             geodesy routines in JavaScript
                     James R. Clynch NPS / 2003
                   
              Done for support of web education pages
    
    
              == must convert inputs to numbers for safety ==
              == if string comes in - sometimes works, sometimes not !==
    */
    
    
    
    
    


    C++实现

    就是根据将JS代码转成C艹.

    GPS 转笛卡尔

    void GPSTransform::gpsPoint2DescartesPoint(const double latitude, const double longitude, const double altitude, double &x;, double &y;, double &z;)
    {
    	//wgs84 WGS84 Earth Constants
    	double wgs84a = 6378.137;
    	double wgs84f = 1.0 / 298.257223563;
    	double wgs84b = wgs84a * (1.0 - wgs84f);
    
    	//earthcon
    	double f = 1 - wgs84b / wgs84a;
    	double eccsq = 1 - (wgs84b* wgs84b) / (wgs84a * wgs84a);
    	double ecc = sqrt(eccsq);
    	double esq = ecc * ecc;
    
    	//llhxyz
    	double dtr = M_PI / 180.0;
    	//qDebug() << dtr << gpsPoint.latitude << endl;
    	double clat = cos(dtr * latitude);
    	double slat = sin(dtr * latitude);
    	double clon = cos(dtr * longitude);
    	double slon = sin(dtr * longitude);
    	//qDebug() << clat << slon << endl;
    
    	//radcur compute the radii at the geodetic latitude lat (in degrees)
    	double dsq = 1.0 - eccsq * slat *slat;
    	double d = sqrt(dsq);
    	//qDebug() << d;
    	double rn = wgs84a / d;
    	double rm = rn * (1.0 - eccsq) / dsq;
    
    	double rho = rn * clat;
    	double zz = (1.0 - eccsq) * rn *slat;
    	double rsq = rho * rho + zz*zz;
    	double r = sqrt(rsq);
    
    	x = (rn + altitude) * clat * clon;
    	y = (rn + altitude) * clat * slon;
    	z = ((1 - esq)*rn + altitude) * slat;
    }


    运行结果





    验证网站

    Geodetic to Cartesian Converter - http://www.apsalin.com/convert-geodetic-to-cartesian.aspx

    atitude,Longitude,Height to/from ECEF (X,Y,Z) - http://www.oc.nps.edu/oc2902w/coord/llhxyz.htm





沪ICP备19023445号-2号
友情链接