大地坐标与地心坐标相互转换 (WGS84,西安80,北京54, China200)C++

Date 2019/04/09 Add by WJB

我们先了解一下大地坐标系。

地心坐标:地心坐标系(geocentric coordinate system )以地球质心为原点建立的空间直角坐标系,或以球心与地球质心重合的地球椭球面为基准面所建立的大地坐标系;以地球质心(总椭球的几何中心)为原点的大地坐标系。通常分为地心空间直角坐标系(以x,y,z为其坐标元素)。

大地坐标系:大地坐标(Geodetic coordinate)是大地测量中以参考椭球面为基准面的坐标,地面点P的位置用大地经度L、大地纬度B和大地高H表示。大地坐标多应用于大地测量学,测绘学等。

参考椭球体是一个数学上定义的地球表面,它近似于大地水准面。 由于其相对简单,参考椭球是大地控制网计算和显示点坐标(如纬度经度海拔)的首选的地球表面的几何模型。通常所说地球的形状和大小,实际上就是以参考椭球体的长半轴、短半轴和扁率来表示的。

常见椭球体:

北京54:克拉索夫椭球体;西安80:1975国际椭球体,China2000:2000中国大地坐标系。

坐标转换公式:

 

代码:地心转大地

#include<math.h>

double targetH, targetB, targetL;
 void XYZtoBLH(double X, double Y, double Z, double aAxis, double bAxis) {
	double e1 = (pow(aAxis, 2) - pow(bAxis, 2)) / pow(aAxis, 2);
	double e2 = (pow(aAxis, 2) - pow(bAxis, 2)) / pow(bAxis, 2);

	double S = sqrt(pow(X, 2) + pow(Y, 2));
	double cosL = X / S;
	double B = 0;
	double L = 0;

	L = acos(cosL);
	L =fabs(L);

	double tanB = Z / S;
	B = atan(tanB);
	double c = aAxis * aAxis / bAxis;
	double preB0 = 0.0;
	double ll = 0.0;
	double N = 0.0;
	//迭代计算纬度
	do {
		preB0 = B;
		ll =pow(cos(B), 2) * e2;
		N = c / sqrt(1 + ll);

		tanB = (Z + N * e1 *sin(B)) / S;
		B = atan(tanB);
	} while (fabs(preB0 - B) >= 0.0000000001);

	ll = pow(cos(B), 2) * e2;
	N = c /sqrt(1 + ll);

	targetH = s /cos(B) - N * (1 - e1);
	targetB = B * 180 / M_PI;
	targetL = L * 180 / M_PI;
}

代码:地心坐标转大地坐标

 double targetX, targetY, targetZ;
 void BLHtoXYZ(double B, double L, double H, double aAxis, double bAxis) {
	 double dblD2R = M_PI / 180;
	 double e1 = sqrt(pow(aAxis, 2) - pow(bAxis, 2)) / aAxis;

	 double N = aAxis / sqrt(1.0 - pow(e1, 2) * pow(sin(B * dblD2R), 2));
	 targetX = (N + H) * cos(B * dblD2R) * cos(L * dblD2R);
	 targetY = (N + H) * cos(B * dblD2R) * sin(L * dblD2R);
	 targetZ = (N * (1.0 - pow(e1, 2)) + H) * sin(B * dblD2R);
 }

 

 

 

 

  • 24
    点赞
  • 168
    收藏
    觉得还不错? 一键收藏
  • 20
    评论
好的,我可以为您提供一个基本的 Python 代码来实现大地坐标地心直角坐标相互转换。以下是代码: ```python import math a = 6378137.0 # 长半轴 b = 6356752.3142 # 短半轴 f = (a - b) / a # 扁率 e_sq = f * (2-f) # 第一偏心率平方 def geodetic_to_geocentric(lat, lon, h): """ 大地坐标转换地心直角坐标 :param lat: 纬度,单位:度 :param lon: 经度,单位:度 :param h: 高度,单位:米 :return: (x, y, z) 地心直角坐标,单位:米 """ # 先将经纬度转为弧度 lat_r = math.radians(lat) lon_r = math.radians(lon) # 计算半径曲率半径 N = a / math.sqrt(1 - e_sq * math.sin(lat_r)**2) # 计算地心直角坐标 x = (N + h) * math.cos(lat_r) * math.cos(lon_r) y = (N + h) * math.cos(lat_r) * math.sin(lon_r) z = ((1 - e_sq) * N + h) * math.sin(lat_r) return x, y, z def geocentric_to_geodetic(x, y, z): """ 地心直角坐标转换大地坐标 :param x: 地心直角坐标 x,单位:米 :param y: 地心直角坐标 y,单位:米 :param z: 地心直角坐标 z,单位:米 :return: (lat, lon, h) 大地坐标,单位:度、度、米 """ # 计算经纬度 lon = math.atan2(y, x) p = math.sqrt(x**2 + y**2) lat = math.atan2(z, p) # 逐次逼近计算高度 e = math.sqrt(e_sq) N = a h = 0 for i in range(10): sin_lat = math.sin(lat) N = a / math.sqrt(1 - e_sq * sin_lat**2) h = p / math.cos(lat) - N lat = math.atan2(z, p * (1 - e_sq * N / (N + h))) # 将弧度转为角度 lat_d = math.degrees(lat) lon_d = math.degrees(lon) return lat_d, lon_d, h ``` 使用方法: ```python # 大地坐标地心直角坐标 lat = 30.0 lon = 120.0 h = 100.0 x, y, z = geodetic_to_geocentric(lat, lon, h) print(x, y, z) # 地心直角坐标大地坐标 lat, lon, h = geocentric_to_geodetic(x, y, z) print(lat, lon, h) ``` 注意:该代码仅适用于 WGS-84 椭球体,其他椭球体需要进行修改。
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值