坐标转换系列二 基于开源的proj4实现

                           坐标转换系列二 基于开源的proj4
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <sstream>
#include <string>
#include "./proj4/include/proj_api.h"
#pragma comment(lib,"./proj4/lib/proj_i.lib")
using namespace std;

int main()
{
	const char* wgs84 = "+proj=latlong +ellps=WGS84 +datum=NAD83";
	const char* beijing1954 = "+proj=tmerc +ellps=krass +x_0=500000.0000000000 +y_0=0 +towgs84=77,-88,-99,0,0,0,0 +lon_0=111e +lat_0=0.0000000000 +units=m +no_defs";
	projPJ pj_wgs84 = pj_init_plus(wgs84);
	projPJ pj_bj54 = pj_init_plus(beijing1954);
	double x = 106.48260558;
	double y = 38.64279675;
	double z = 0;
	x *= DEG_TO_RAD;
	y *= DEG_TO_RAD;
	pj_transform(pj_wgs84, pj_bj54, 1, 1, &x, &y, NULL);
	cout.setf(ios::fixed);
	cout.precision(9);
	cout.width(12);
	cout << x << "\t" << y << "\t" << z << endl;
}

程序运行结果如下所示:
proj4计算的结果
1、本程序基于proj4开源库,基于x86平台;
2、定义原始坐标系字符串const char* wgs84;
3、定义目标坐标系字符串const char* beijing1954;
4、分别构造projPJ;
5、将经纬度转换为弧度;
6、调用pj_transform函数,进行坐标转换;
7、转换结果输出并显示。

结论1:该篇文章介绍的坐标转换流程清晰、简洁;较上篇文章实用性更强。
结论2:两篇文章介绍的转换方法均能实现目标,精度相当。
结论3:多线程中推荐使用本文介绍的方法。
结论4:源码下载地址为:https://download.csdn.net/download/m0_38122606/15533345

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值