zoukankan      html  css  js  c++  java
  • 使用Proj库进行大地坐标转空间坐标、投影坐标的一个示例

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

    void demoPROJ()
    {
    	const char* wgs84 = "+proj=tmerc +ellps=WGS84 +lon_0=117e +x_0=500000 +y_0=0 +k=1.0";//+datum=WGS84 
    
    	projPJ pj;
    
    	if (!(pj = pj_init_plus(wgs84)))
    	{
    		exit(-1);
    	}
    
    	projUV pt[2] = {{116.987, 39.2333}, {116.987654321, 39.453}};
    
    	for (int i = 0; i < 2; i++)
    	{
    		cout << "第" << i + 1 << "个点的转换:
    ";
    		projUV	pjPt;
    		pt[i].u *= DEG_TO_RAD;
    		pt[i].v *= DEG_TO_RAD;
    		pjPt = pj_fwd(pt[i], pj);
    		cout.setf(ios::fixed);
    		cout.precision(4);
    		cout.width(12);
    		cout << "	经纬度转换为坐标
    	";
    		cout << pjPt.u << "	" << pjPt.v << endl;
    
    		pjPt = pj_inv(pjPt, pj);
    		cout.setf(ios::fixed);
    		cout.precision(9);
    		cout.width(12);
    		cout << "	坐标转换为经纬度
    	";
    		cout << pjPt.u * RAD_TO_DEG << "	" << pjPt.v * RAD_TO_DEG << endl;
    	}
    	cout << endl;
    
    	double wgs84_a = 6378137.0;
    	double wgs84_e = 0.00669437999013; // 在这里e是第一偏心率的平方
    
    	projUVW pt3[2] = {{116.5164884833, 39.7663036028,  23.220}, {116.987654321, 39.453, 18}};
    	for (int i = 0; i < 2; i++)
    	{
    		cout << "第" << i + 3 << "个点的转换:
    ";
    		pt3[i].u *= DEG_TO_RAD;
    		pt3[i].v *= DEG_TO_RAD;
    
    		pj_geodetic_to_geocentric(wgs84_a, wgs84_e, 1, 1, &pt3[i].u, &pt3[i].v, &pt3[i].w);
    		cout.setf(ios::fixed);
    		cout.precision(4);
    		cout.width(12);
    		cout << "	经纬度转换为空间坐标
    	";
    		cout << pt3[i].u << "	" << pt3[i].v << "	" << pt3[i].w << endl;
    
    		pj_geocentric_to_geodetic(wgs84_a, wgs84_e, 1, 1, &pt3[i].u, &pt3[i].v, &pt3[i].w);
    		cout.setf(ios::fixed);
    		cout.precision(9);
    		cout.width(12);
    		cout << "	空间坐标转换为经纬度
    	";
    		cout << pt3[i].u * RAD_TO_DEG << "	" << pt3[i].v * RAD_TO_DEG << "	" ;
    		cout.precision(4);
    		cout << pt3[i].w << endl;
    	}
    
    	pj_free(pj);
    }
    

      

  • 相关阅读:
    ASP.NET MVC学习笔记-----ActionInvoker
    quartz启动报错
    THUSC 2021 游记
    C++下随机数的生成
    友链
    memset一些技巧
    CodeForces Round #705 总结&题解
    php计算两坐标距离
    vue中使用keepAlive组件缓存遇到的坑
    vue 中 keepAlive
  • 原文地址:https://www.cnblogs.com/xingzhensun/p/6148809.html
Copyright © 2011-2022 走看看