使用Proj库进行大地坐标转空间坐标、投影坐标的一个示例

本文介绍了一个使用Proj库进行坐标转换的示例程序。通过该程序,演示了如何将经纬度坐标转换为投影坐标及空间直角坐标,并实现了逆向转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近研究了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 << "个点的转换:\n";
		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 << "\t经纬度转换为坐标\n\t";
		cout << pjPt.u << "\t" << pjPt.v << endl;

		pjPt = pj_inv(pjPt, pj);
		cout.setf(ios::fixed);
		cout.precision(9);
		cout.width(12);
		cout << "\t坐标转换为经纬度\n\t";
		cout << pjPt.u * RAD_TO_DEG << "\t" << 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 << "个点的转换:\n";
		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 << "\t经纬度转换为空间坐标\n\t";
		cout << pt3[i].u << "\t" << pt3[i].v << "\t" << 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 << "\t空间坐标转换为经纬度\n\t";
		cout << pt3[i].u * RAD_TO_DEG << "\t" << pt3[i].v * RAD_TO_DEG << "\t" ;
		cout.precision(4);
		cout << pt3[i].w << endl;
	}

	pj_free(pj);
}

  

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值