Proj.4的使用示例

更多关于Proj.4的信息见http://hi.baidu.com/liongg/blog/item/8e0a92457e136a3a879473ce.html

#include "proj/proj_api.h"
#include <iostream>
//#pragma comment(lib,"..\\debug\\proj_i.lib")
using namespace std;

char* beijing1954="+proj=tmerc +ellps=krass +lon_0=116.35025181e +lat_0=39.86576583n +x_0=500000 +y_0=300000 +units=m +k=1.0 +towgs84=22,-118,30.5,0,0,0,0";

projPJ pj = NULL;

void projInit()
{
  if (!(pj = pj_init_plus(beijing1954))) exit(1);
}

void projFree()
{
  pj_free(pj);
}


void gaussProjInv(double X, double Y, double *longitude, double *latitude)
{
    projUV p;
  
    p.u = X;
    p.v = Y;
    p=pj_inv(p,pj);
    cout.setf(ios_base::fixed);
    p.u/=DEG_TO_RAD;
    p.v/=DEG_TO_RAD;
    
    //cout<<"pj_inv result:    "<<p.u<<"    "<<p.v<<endl;

    *longitude = p.u;
    *latitude = p.v;
}


void gaussProjFwd(double X, double Y, double *x2, double *y2)
{
  projUV p;

  p.u = X * DEG_TO_RAD;
  p.v = Y * DEG_TO_RAD;
  p=pj_fwd(p,pj);
  cout.setf(ios_base::fixed);
  //p.u/=DEG_TO_RAD;
  //p.v/=DEG_TO_RAD;

  //cout<<"pj_inv result:    "<<p.u<<"    "<<p.v<<endl;

  *x2 = p.u;
  *y2 = p.v;
}

其中那个很长很长的字符串是转换参数。

 

 

你可能感兴趣的:(Proj.4)