调用proj.4库

proj.4的库非常简单,很容易使用。

用法:

#include <proj_api.h>

projPJ pj_init(int argc, char **argv)

projPJ pj_init_plus(const char *defn)

projUV pj_fwd(projUV val, projPJ proj)

projUV pj_inv(projUV val, projPJ proj)

int pj_transform(projPJ src_cs, projPJ dst_cs, long point_count,
double *x, double *y, double *z)

void pj_free(projPJ proj)

说明:
pj_fwd用于从经纬度转换到公里网,pj_inv则相反,注意这两个函数都是在同一个椭球下进行处理的。
pj_transform则用于两个坐标系之间的转换,包括两个不同椭球体之间的转换(datum shift)。
一个简单的c++测试程序:

#include <proj_api.h>
#include <iostream>
using namespace std;
//compile: g++ *.cpp -o proj -lproj

main(int argc, char **argv) {
const char* beijing1954="+proj=tmerc +ellps=krass +x_0=18500000 +y_0=0 +lat_0=0 +lon_0=105 +units=m +k=1.0";
//if you want to convert to wgs84 datum
//"+towgs84=22,-118,30.5,0,0,0,0"
projUV p;
projPJ pj;

if (!(pj = pj_init_plus(beijing1954))) exit(1);
p.u=103.6*DEG_TO_RAD;
p.v=36.11*DEG_TO_RAD;
p=pj_fwd(p,pj);
cout.setf(ios_base::fixed);
cout<<"Beijing 1954, (103.60,36.11)"<<endl;
cout<<"pj_fwd result:"<<p.u<<" "<<p.v<<endl;
p=pj_inv(p,pj);
p.u/=DEG_TO_RAD;
p.v/=DEG_TO_RAD;
cout<<"pj_inv result:"<<p.u<<" "<<p.v<<endl;
pj_free(pj);
exit(0);
}

This entry was posted in GIS, Linux and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string w1YYaw to the field below:

以新浪微博帐号登录