wgs84转任意中央子午线cgcs2000 vba代码
时间: 2023-07-30 11:06:29 浏览: 119
以下是将WGS84坐标系转换为任意中央子午线CGCS2000坐标系的VBA代码:
```
Function WGS84ToCGCS2000(longitude As Double, latitude As Double, altitude As Double, centralMeridian As Double) As Variant
Dim a As Double, b As Double, f 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 - centralMeridian) * Cos(latitude)
B = latitude
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(0) * Sin(0))
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(centralMeridian) - delta_Z * Cos(centralMeridian)
dY = delta_Y * Cos(centralMeridian) - delta_Z * Sin(centralMeridian)
dZ = delta_X
'返回结果
WGS84ToCGCS2000 = Array(X + dX, Y + dY, Z + dZ)
End Function
```
这段代码会返回一个包含三个元素的数组,分别是转换后的X、Y、Z坐标。其中longitude、latitude、altitude分别为WGS84的经度、纬度和高度,单位为度和米;centralMeridian为目标坐标系的中央子午线经度,单位为度。需要注意的是,本代码仅适用于中国境内的坐标转换,如果需要进行其他地区的转换,需要根据实际情况进行修改。
阅读全文