CGCS2000坐标系与WGS84的相互投影转换java
时间: 2023-11-04 11:08:07 浏览: 144
CGCS2000坐标系和WGS84坐标系都是大地坐标系,它们之间的转换可以使用数学公式进行计算。以下是Java代码实现CGCS2000坐标系与WGS84坐标系的相互投影转换:
```java
public class CoordinateTransformation {
private static final double a = 6378137.0; // 长轴半径
private static final double b = 6356752.3142; // 短轴半径
private static final double f = 1 / 298.257222101; // 扁率
private static final double e2 = (a * a - b * b) / (a * a); // 第一偏心率平方
private static final double e12 = (a * a - b * b) / (b * b); // 第二偏心率平方
/**
* CGCS2000坐标系转WGS84坐标系
*
* @param x CGCS2000坐标系X轴坐标
* @param y CGCS2000坐标系Y轴坐标
* @param z CGCS2000坐标系Z轴坐标
* @return WGS84坐标系经纬度和高程,数组下标0为经度,1为纬度,2为高程
*/
public static double[] CGCS2000toWGS84(double x, double y, double z) {
double delta_x = -146.415;
double delta_y = 507.404;
double delta_z = 681.686;
double m = x - delta_x;
double n = y - delta_y;
double p = z - delta_z;
double B0 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12));
double B1 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B0) * Math.sin(B0)));
double B2 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B1) * Math.sin(B1)));
double B3 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B2) * Math.sin(B2)));
double B4 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B3) * Math.sin(B3)));
double B5 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B4) * Math.sin(B4)));
double B6 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B5) * Math.sin(B5)));
double B7 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B6) * Math.sin(B6)));
double B8 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B7) * Math.sin(B7)));
double B9 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B8) * Math.sin(B8)));
double B10 = Math.atan(p / Math.sqrt(m * m + n * n) * (1 - f + e12 * Math.sin(B9) * Math.sin(B9)));
double N = a / Math.sqrt(1 - e2 * Math.sin(B10) * Math.sin(B10));
double H = Math.sqrt(m * m + n * n) / Math.cos(B10) - N;
double L = Math.atan(n / m);
if (m < 0) {
L = L + Math.PI;
} else if (m > 0 && n < 0) {
L = L + 2 * Math.PI;
}
double lng = L * 180 / Math.PI;
double lat = B10 * 180 / Math.PI;
double alt = H;
return new double[]{lng, lat, alt};
}
/**
* WGS84坐标系转CGCS2000坐标系
*
* @param lng WGS84坐标系经度
* @param lat WGS84坐标系纬度
* @param alt WGS84坐标系高程
* @return CGCS2000坐标系X轴、Y轴、Z轴坐标,数组下标0为X轴坐标,1为Y轴坐标,2为Z轴坐标
*/
public static double[] WGS84toCGCS2000(double lng, double lat, double alt) {
double B = lat * Math.PI / 180.0;
double L = lng * Math.PI / 180.0;
double H = alt;
double N = a / Math.sqrt(1 - e2 * Math.sin(B) * Math.sin(B));
double X = (N + H) * Math.cos(B) * Math.cos(L);
double Y = (N + H) * Math.cos(B) * Math.sin(L);
double Z = (N * (1 - e2) + H) * Math.sin(B);
double delta_x = -146.415;
double delta_y = 507.404;
double delta_z = 681.686;
X = X + delta_x;
Y = Y + delta_y;
Z = Z + delta_z;
return new double[]{X, Y, Z};
}
}
```
其中,`CGCS2000toWGS84`方法实现CGCS2000坐标系转WGS84坐标系,输入参数为CGCS2000坐标系的X轴坐标、Y轴坐标和Z轴坐标,返回值为WGS84坐标系的经纬度和高程。`WGS84toCGCS2000`方法实现WGS84坐标系转CGCS2000坐标系,输入参数为WGS84坐标系的经度、纬度和高程,返回值为CGCS2000坐标系的X轴坐标、Y轴坐标和Z轴坐标。
阅读全文