Proj学习

最近研究了proj库的使用,自己写了一个小demo,仅供参考。


     
     
  1. void demoPROJ()
  2. {
  3. const char* wgs84 = "+proj=tmerc +ellps=WGS84 +lon_0=117e +x_0=500000 +y_0=0 +k=1.0"; //+datum=WGS84
  4. projPJ pj;
  5. if (!(pj = pj_init_plus(wgs84)))
  6. {
  7. exit( -1);
  8. }
  9. projUV pt[ 2] = {{ 116.987, 39.2333}, { 116.987654321, 39.453}};
  10. for ( int i = 0; i < 2; i++)
  11. {
  12. cout << "第" << i + 1 << "个点的转换:\n";
  13. projUV pjPt;
  14. pt[i].u *= DEG_TO_RAD;
  15. pt[i].v *= DEG_TO_RAD;
  16. pjPt = pj_fwd(pt[i], pj);
  17. cout. setf(ios::fixed);
  18. cout. precision( 4);
  19. cout. width( 12);
  20. cout << "\t经纬度转换为坐标\n\t";
  21. cout << pjPt.u << "\t" << pjPt.v << endl;
  22. pjPt = pj_inv(pjPt, pj);
  23. cout. setf(ios::fixed);
  24. cout. precision( 9);
  25. cout. width( 12);
  26. cout << "\t坐标转换为经纬度\n\t";
  27. cout << pjPt.u * RAD_TO_DEG << "\t" << pjPt.v * RAD_TO_DEG << endl;
  28. }
  29. cout << endl;
  30. double wgs84_a = 6378137.0;
  31. double wgs84_e = 0.00669437999013; // 在这里e是第一偏心率的平方
  32. projUVW pt3[ 2] = {{ 116.5164884833, 39.7663036028, 23.220}, { 116.987654321, 39.453, 18}};
  33. for ( int i = 0; i < 2; i++)
  34. {
  35. cout << "第" << i + 3 << "个点的转换:\n";
  36. pt3[i].u *= DEG_TO_RAD;
  37. pt3[i].v *= DEG_TO_RAD;
  38. pj_geodetic_to_geocentric(wgs84_a, wgs84_e, 1, 1, &pt3[i].u, &pt3[i].v, &pt3[i].w);
  39. cout. setf(ios::fixed);
  40. cout. precision( 4);
  41. cout. width( 12);
  42. cout << "\t经纬度转换为空间坐标\n\t";
  43. cout << pt3[i].u << "\t" << pt3[i].v << "\t" << pt3[i].w << endl;
  44. pj_geocentric_to_geodetic(wgs84_a, wgs84_e, 1, 1, &pt3[i].u, &pt3[i].v, &pt3[i].w);
  45. cout. setf(ios::fixed);
  46. cout. precision( 9);
  47. cout. width( 12);
  48. cout << "\t空间坐标转换为经纬度\n\t";
  49. cout << pt3[i].u * RAD_TO_DEG << "\t" << pt3[i].v * RAD_TO_DEG << "\t" ;
  50. cout. precision( 4);
  51. cout << pt3[i].w << endl;
  52. }
  53. pj_free(pj);
  54. }

  

转载于:https://www.cnblogs.com/xingzhensun/p/6148809.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值