java utm坐标转经纬度,utm坐标和经纬度相互转换
时间: 2023-09-21 18:11:32 浏览: 33
Java中可以使用第三方库或手动实现UTM坐标和经纬度的相互转换。
1. 使用第三方库
可以使用JCoord库,它提供了UTM坐标和经纬度之间的转换方法。以下是一个示例:
```
UTMRef utm = new UTMRef(32, 'N', 448251, 5411932);
LatLong latLong = utm.toLatLong();
double latitude = latLong.getLat();
double longitude = latLong.getLng();
```
2. 手动实现
手动实现UTM坐标和经纬度之间的转换需要进行复杂的计算,可以参考以下代码:
```
public static double[] UTMtoLL(double UTMNorthing, double UTMEasting, String UTMZone) {
double k0 = 0.9996;
double a = 6378137.0;
double eccSquared = 0.00669438;
double eccPrimeSquared;
double e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
double N1, T1, C1, R1, D, M;
double[] LL = new double[2];
double pi = 3.14159265;
double zoneNumber = Double.parseDouble(UTMZone.substring(0, UTMZone.length() - 1));
double zoneLetter = UTMZone.charAt(UTMZone.length() - 1);
double northing = UTMNorthing;
if (zoneLetter == 'S') {
northing = 10000000 - UTMNorthing;
}
double x = UTMEasting - 500000.0;
double y = northing / k0;
N1 = a / Math.sqrt(1 - eccSquared * Math.sin(y * pi / 180) * Math.sin(y * pi / 180));
T1 = Math.tan(y * pi / 180) * Math.tan(y * pi / 180);
C1 = eccPrimeSquared * Math.cos(y * pi / 180) * Math.cos(y * pi / 180);
R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(y * pi / 180) * Math.sin(y * pi / 180), 1.5);
D = x / (N1 * k0);
LL[0] = y * pi / 180 - ((N1 * Math.tan(y * pi / 180) / R1) * ((D * D / 2) - ((1 + 3 * T1 + 2 * C1) * Math.pow(D, 4) / 24)
+ ((5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * Math.pow(D, 6) / 720)));
LL[1] = (D - ((1 + 2 * T1 + C1) * Math.pow(D, 3) / 6)
+ ((5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * Math.pow(D, 5) / 120)) * 180 / pi;
if (zoneNumber < 0) {
zoneNumber = -zoneNumber;
}
LL[0] = LL[0] * 180 / pi;
return LL;
}
public static double[] LLtoUTM(double latitude, double longitude) {
double k0 = 0.9996;
double a = 6378137.0;
double eccSquared = 0.00669438;
double eccPrimeSquared;
double e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
double N1, T1, C1, R1, D, M;
double[] UTM = new double[3];
double zoneNumber;
double LongOrigin;
double eccPrimeSquared1;
double N, T, C, A, M1;
double pi = 3.14159265;
if (latitude < -80 || latitude > 84) {
return null;
}
double LatRad = latitude * pi / 180.0;
double LongRad = longitude * pi / 180.0;
zoneNumber = Math.floor((longitude + 180) / 6) + 1;
LongOrigin = (zoneNumber - 1) * 6 - 180 + 3;
eccPrimeSquared1 = (eccSquared) / (1 - eccSquared);
N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
T = Math.tan(LatRad) * Math.tan(LatRad);
C = eccPrimeSquared1 * Math.cos(LatRad) * Math.cos(LatRad);
A = Math.cos(LatRad) * (LongRad - LongOrigin);
M1 = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad
- (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024)
* Math.sin(2 * LatRad)
+ (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad)
- (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));
UTM[0] = 500000.0 + (k0 * N * (A + (1 - T + C) * Math.pow(A, 3) / 6
+ (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared1) * Math.pow(A, 5) / 120));
UTM[1] = (k0 * (M1 + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * Math.pow(A, 4) / 24
+ (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared1) * Math.pow(A, 6) / 720))) + 1000000.0 * zoneNumber;
UTM[2] = zoneNumber;
if (latitude < 0) {
UTM[1] += 10000000.0;
}
return UTM;
}
```
其中,`UTMtoLL`方法将UTM坐标转换为经纬度,`LLtoUTM`方法将经纬度转换为UTM坐标。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![xlsm](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)