song.yz@foxmail.com wechat: math-box

blog



地理坐标系与地固坐标系转换



由geocentric与geodetic之间的转换是大地测量中的基本工具,后者转为前者是显示表达式,反正则是非线性方程,原则上要求迭代处理。 在sofa中已经提供了两者的转换,可以将其编译为常用小工具。 geocentric转为geodetic为
  
/*------------------------------------------------------
   Versions and Changes :

    Transform geocentric coordinates to geodetic using the WGS84 ellipsoid

    complie command:
    g++ -o gc2gd.exe   gc2gd.cpp ./sofalib/*.c

  ***  caution  ***
    don't complie t_sofa_c 
    remove t_sofa_c.c  in sofalib , or change the name 
--------------------------------------------------------
   Author      : Song Yates           
   Copyrigt(C) : Shanghai Astronomical Observatory, CAS
                (All rights reserved)             2023
-------------------------------------------------------*/
#include 
#include "./sofalib/sofa.h"
using namespace std;
int main(int argc, char **argv)
{
    if (argc == 1) 
    {
        printf("%s","\n");
        printf("%s","Transform geocentric coordinates to geodetic \n");
        printf("%s","the reference ellipsoid is WGS84 \n");
        printf("%s","usage :    \n");
        printf("%s","gc2gd x y z (in meters) \n");
        return 0;
    }
    double XYZ[3];
    sscanf(argv[1],"%lf",&XYZ[0]);
    sscanf(argv[2],"%lf",&XYZ[1]);
    sscanf(argv[3],"%lf",&XYZ[2]);    
    printf("%s","\n");
    printf("%s","XYZ =      (in meters) \n");
    printf("%18lf  %18lf  %18lf \n \n", XYZ[0],XYZ[1],XYZ[2]);    
    double elong,phi,height;
    int itmp;
    itmp = iauGc2gd ( 1, XYZ, &elong, &phi, &height );
    const double pi = 3.141592653589793238462643 ;
    printf("%s","longitude latitude and height  =      (in arc and  meters) \n");
    printf("%18.10lf  %18.10lf  %18.4lf \n \n", elong,phi,height);    
    printf("%s","longitude latitude and height  =      (in degree and  meters) \n");
    printf("%18.10lf  %18.10lf  %18.4lf \n \n", elong*180.0/pi ,phi*180.0/pi ,height);    
    return 0;
}
geodetic 转为geocentric

  /*------------------------------------------------------
     Versions and Changes :
    
     Transform geodetic coordinates to geocentric using WGS84
     reference ellipsoid.
  
      complie command:
      g++ -o gd2gc.exe ./sofalib/*.c  gd2gc.cpp
  
  ***  caution  ***
      don't complie t_sofa_c 
      remove t_sofa_c.c  in sofalib , or change the name 
  
 --------------------------------------------------------
     Author      : Song Yates           
     Copyrigt(C) : Shanghai Astronomical Observatory, CAS
                  (All rights reserved)             2023
  -------------------------------------------------------*/  
  #include 
  #include "./sofalib/sofa.h"   
  using namespace std;   
  int main(int argc, char **argv)
  {
      if (argc == 1) 
      {
          printf("%s","\n");
          printf("%s","Transform geodetic coordinates to geocentric \n");
          printf("%s","the reference ellipsoid is WGS84 \n");
          printf("%s","usage :    \n");
          printf("%s","gc2gd  longitude latitude  height (in degree and meters) \n");
          return 0;
      }      
      double XYZ[3];
      double elong,phi,height;
      int itmp;
      const double pi = 3.141592653589793238462643 ;
      sscanf(argv[1],"%lf",&elong);
      sscanf(argv[2],"%lf",&phi);
      sscanf(argv[3],"%lf",&height);      
      printf("%s","\n");
      printf("%s","longitude latitude and height  =      (in degree and  meters) \n");
      printf("%18lf  %18lf  %18lf \n \n", elong,phi,height); 
      itmp =iauGd2gc ( 1,   elong*pi/180.0,  phi*pi/180.0,  height, XYZ);      
      printf("%s","longitude latitude and height  =      (in arc and  meters) \n");
      printf("%18lf  %18lf  %18lf \n \n", elong*pi/180.0 ,phi*pi/180.0 ,height);        
      printf("%s","XYZ =      (in meters) \n");
      printf("%18.4lf  %18.4lf  %18.4lf \n \n", XYZ[0],XYZ[1],XYZ[2]);   
      return 0;
  }