Wgs84转cgcs2000c++代码
时间: 2023-03-15 17:46:18 浏览: 327
您可以使用PROJ 来实现WGS84到CGCS2000C的转换,其代码为:+proj=tmerc +lon_0=117 +lat_0=0 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +towgs84=0,0,0,0,0,0,0 +a=6378140 +rf=298.257 +to_meter=1。
相关问题
wgs84转cgcs2000 vba代码
以下是将WGS84坐标系转换为CGCS2000坐标系的VBA代码:
```
Function WGS84ToCGCS2000(latitude As Double, longitude As Double, altitude As Double) As Variant
Dim a As Double, f As Double, b As Double, e As Double, N As Double, X As Double, Y As Double, Z As Double
Dim a0 As Double, a2 As Double, a4 As Double, a6 As Double, a8 As Double, M As Double, T As Double, C As Double, A As Double, B As Double, E As Double, W As Double, N0 As Double, K As Double
Dim delta_X As Double, delta_Y As Double, delta_Z As Double, dX As Double, dY As Double, dZ As Double
'WGS84椭球体参数
a = 6378137
f = 1 / 298.257223563
b = a * (1 - f)
e = Sqr(2 * f - f * f)
'CGCS2000椭球体参数
a0 = 6378137
a2 = -0.000000000000000000000000000003405
a4 = 0.000000000000000000000000001550
a6 = -0.000000000000000000000000000004870
a8 = 0.000000000000000000000000000000016
'计算经纬度对应的参数
N = a / Sqr(1 - e * e * Sin(latitude) * Sin(latitude))
X = (N + altitude) * Cos(latitude) * Cos(longitude)
Y = (N + altitude) * Cos(latitude) * Sin(longitude)
Z = (N * (1 - e * e) + altitude) * Sin(latitude)
'计算转换参数
M = a0 * (1 - e * e) * (a0 * (1 - e * e) / (b * b) - 1)
T = Tan(latitude)
C = e * Cos(latitude) * Cos(latitude) / (1 - e * e)
A = (longitude - 111) * Cos(latitude)
B = (latitude - 35) * 111
E = (a2 * Sin(2 * latitude) + a4 * Sin(4 * latitude) + a6 * Sin(6 * latitude) + a8 * Sin(8 * latitude)) / 10 ^ 6
W = M / (a0 * (1 - e * e)) / (1 - e * e * Sin(latitude) * Sin(latitude))
N0 = a0 / Sqr(1 - e * e * Sin(35 * Pi / 180) * Sin(35 * Pi / 180))
K = 1 + (A * A / 2 + (5 - T * T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T * T + T * T * T * T) * A * A * A * A * A * A / 720) * (B * B) / 10 ^ 6
'计算坐标转换
delta_X = -W * X + K + E
delta_Y = -W * Y
delta_Z = -W * Z
dX = -delta_Y * Sin(35 * Pi / 180) - delta_Z * Cos(35 * Pi / 180)
dY = delta_Y * Cos(35 * Pi / 180) - delta_Z * Sin(35 * Pi / 180)
dZ = delta_X
'返回结果
WGS84ToCGCS2000 = Array(X + dX, Y + dY, Z + dZ)
End Function
```
这段代码会返回一个包含三个元素的数组,分别是转换后的X、Y、Z坐标。其中latitude、longitude、altitude分别为WGS84的纬度、经度和高度,单位为度和米。需要注意的是,本代码仅适用于中国境内的坐标转换,如果需要进行其他地区的转换,需要根据实际情况进行修改。
wgs84转CGCS2000 c++代码
您可以使用以下的 C 代码将 WGS84 坐标转换为 CGCS2000 坐标:
```c
#include <stdio.h>
#include <math.h>
const double a = 6378137.0; // WGS84 椭球长半轴
const double f = 1 / 298.257223563; // WGS84 椭球扁率
const double b = a * (1 - f); // WGS84 椭球短半轴
const double e2 = (pow(a,2) - pow(b, 2)) / pow(a, 2); // WGS84 椭球第一偏心率的平方
const double a_cgcs = 6378137.0; // CGCS2000 椭球长半轴
const double f_cgcs = 1 / 298.257222101; // CGCS2000 椭球扁率
const double b_cgcs = a_cgcs * (1 - f_cgcs); // CGCS2000 椭球短半轴
const double e2_cgcs = (pow(a_cgcs, 2) - pow(b_cgcs, 2)) / pow(a_cgcs,2); // CGCS2000 椭球第一偏心率的平方
double deg2rad(double degree) {
return degree * M_PI / 180.0;
}
double rad2deg(double radian) {
return radian * 180.0 / M_PI;
}
void wgs84ToCgcs2000(double lon_wgs84, double lat_wgs84, double height_wgs84,
double *lon_cgcs, double *lat_cgcs, double *height_cgcs) {
double lon_rad = deg2rad(lon_wgs84);
double lat_rad = deg2rad(lat_wgs84);
double N = a_cgcs / sqrt(1 - e2_cgcs * pow(sin(lat_rad), 2));
double X = (N + height_wgs84) * cos(lat_rad) * cos(lon_rad);
double Y = (N + height_wgs84) * cos(lat_rad) * sin(lon_rad);
double Z = (N * (1 - e2_cgcs) + height_wgs84) * sin(lat_rad);
double p = sqrt(pow(X, 2) + pow(Y, 2));
if (p < 1e-10) {
*lon_cgcs = 0;
*lat_cgcs = 0;
*height_cgcs = Z;
} else {
double theta = atan(Z / (p * (1 - e2_cgcs)));
double sin_theta = sin(theta);
double cos_theta = cos(theta);
*lon_cgcs = atan(Y / X);
*lat_cgcs = atan((Z + b_cgcs * e2_cgcs * pow(sin_theta, 3)) /
(p - a_cgcs * e2_cgcs * pow(cos_theta, 3)));
*height_cgcs = p / cos(*lat_cgcs) - a_cgcs / sqrt(1 - e2_cgcs * pow(sin(*lat_cgcs), 2));
}
*lon_cgcs = rad2deg(*lon_cgcs);
*lat_cgcs = rad2deg(*lat_cgcs);
}
int main() {
double lon_wgs84 = 116.3976;
double lat_wgs84 = 39.9037;
double height_wgs84 = 0.0;
double lon_cgcs, lat_cgcs, height_cgcs;
wgs84ToCgcs2000(lon_wgs84, lat_wgs84, height_wgs84, &lon_cgcs, &lat_cgcs, &height_cgcs);
printf("CGCS2000 坐标:\n");
printf("经度:%f\n", lon_cgcs);
printf("纬度:%f\n", lat_cgcs);
printf("高程:%f\n", height_cgcs);
return 0;
}
```
阅读全文