• 博客等级：
• 博客积分：0
• 博客访问：7
• 关注人气：2
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

WGS84经纬度坐标与TWD67、TWD97的TM2坐标转换

(2007-08-28 22:47:45)

gis

public class Coordinate {
private static double DEG_RAD = 0.01745329251994329572e0;

private static double TWD97_A = 6378137.0e0;

private static double TWD97_ECC = 0.00669438002290e0;

private static double TWD97_ECC2 = 0.00673949677556e0;

private static double TWD97_TM2 = 0.9999e0;

public double mercator(double y, double a, double ecc) {
if (y == 0.0) {
return 0.0;
} else {
return a
* ((1.0 - ecc / 4.0 - 3.0 * ecc * ecc / 64.0 - 5.0 * ecc
* ecc * ecc / 256.0)
* y
- (3.0 * ecc / 8.0 + 3.0 * ecc * ecc / 32.0 + 45.0
* ecc * ecc * ecc / 1024.0)
* Math.sin(2.0 * y)
+ (15.0 * ecc * ecc / 256.0 + 45.0 * ecc * ecc
* ecc / 1024.0) * Math.sin(4.0 * y) - (35.0
* ecc * ecc * ecc / 3072.0)
* Math.sin(6.0 * y));
}
}

//WGS84经纬度坐标转换为TWD97 Tm2坐标
public HanLonLat toTwd97TM2(double a, double ecc, double ecc2, double lat,
double lon, double scale, double x, double y) {
double x0, y0, x1, y1, m0, m1;
double n, t, c, A;

m0 = mercator(y1, a, ecc);
m1 = mercator(y0, a, ecc);

n = a / Math.sqrt(1 - ecc * Math.pow(Math.sin(y0), 2.0));
t = Math.pow(Math.tan(y0), 2.0);
c = ecc2 * Math.pow(Math.cos(y0), 2.0);
A = (x0 - x1) * Math.cos(y0);

x = scale
* n
* (A + (1.0 - t + c) * A * A * A / 6.0 + (5.0 - 18.0 * t + t
* t + 72.0 * c - 58.0 * ecc2)
* Math.pow(A, 5.0) / 120.0);
y = scale
* (m1 - m0 + n
* Math.tan(y0)
* (A * A / 2.0 + (5.0 - t + 9.0 * c + 4 * c * c)
* Math.pow(A, 4.0) / 24.0 + (61.0 - 58.0 * t
+ t * t + 600.0 * c - 330.0 * ecc2)
* Math.pow(A, 6.0) / 720.0));
x += 250000;
HanLonLat objHanLonLat = new HanLonLat();
objHanLonLat.setLon(x);
objHanLonLat.setLat(y);
return objHanLonLat;
}

//WGS84经纬度坐标转换为TWD97 Tm2坐标 ——方法调用
public HanLonLat getTwd97TM2LocationFromTwd97(double x, double y) {
HanLonLat objHanLonLat = this.toTwd97TM2(TWD97_A, TWD97_ECC, TWD97_ECC2, 0,
121, TWD97_TM2, x, y);//121为台湾岛的中央经线
return objHanLonLat;
}

////WGS84经纬度坐标转换为TWD67 Tm2坐标
public HanLonLat getTwd67TM2LocationFromTwd97(double x, double y) {
double A = 0.00001549;
double B = 0.000006521;
HanLonLat loncation_97 = this.toTwd97TM2(TWD97_A, TWD97_ECC, TWD97_ECC2, 0,
121, TWD97_TM2, x, y);
double X_97 = loncation_97.getLon();
double Y_97 = loncation_97.getLat();

double X_67 = X_97 - 807.8 - A * X_97 - B * Y_97;
double Y_67 = Y_97 + 248.6 - A * Y_97 - B * X_97;

HanLonLat objHanLonLat = new HanLonLat();
objHanLonLat.setLon(X_67);
objHanLonLat.setLat(Y_67);
return objHanLonLat;
}
}

//自己定义的一个经纬度类

public class HanLonLat {
private double lon;
private double lat;

public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}

}

0