|
@@ -0,0 +1,161 @@
|
|
|
+
|
|
|
+ * @创建人 ccj
|
|
|
+ * @创建时间 2020/7/25
|
|
|
+ * @描述
|
|
|
+ */
|
|
|
+public class GpsConvertMethod {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public double[] coordinatexy;
|
|
|
+
|
|
|
+ public double[] coordinatelb;
|
|
|
+
|
|
|
+ public GpsConvertMethod(String name, double x, double y, double angle, double xShift, double yShift) {
|
|
|
+
|
|
|
+ if(name == "MCT2XY"){
|
|
|
+
|
|
|
+
|
|
|
+ double[] xy = new double[2];
|
|
|
+ xy = MCT84Bl2xy(x,y);
|
|
|
+ double[] normalxy = new double[2];
|
|
|
+ normalxy = xy2normalxy(xy[0],xy[1], angle);
|
|
|
+ coordinatexy = new double[2];
|
|
|
+ coordinatexy = normalxyShiftToxy(normalxy[0],normalxy[1],xShift,yShift);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(name == "XY2MCT"){
|
|
|
+
|
|
|
+
|
|
|
+ double[] normalxy = new double[2];
|
|
|
+ normalxy = xyShiftToNormalxy(x,y,xShift,yShift);
|
|
|
+ double[] xy = new double[2];
|
|
|
+ xy = normalxy2xy(normalxy[0],normalxy[1], angle);
|
|
|
+ coordinatelb = new double[2];
|
|
|
+ coordinatelb = xy2MCT84Bl(xy[0],xy[1]);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double[] MCT84Bl2xy(double lat, double lon) {
|
|
|
+ lon = lon * Math.PI / 180;
|
|
|
+ lat = lat * Math.PI / 180;
|
|
|
+
|
|
|
+ double B0 = 30 * Math.PI / 180;
|
|
|
+
|
|
|
+ double N = 0, e = 0, a = 0, b = 0, e2 = 0, K = 0;
|
|
|
+ a = 6378137;
|
|
|
+ b = 6356752.3142;
|
|
|
+ e = Math.sqrt(1 - (b / a) * (b / a));
|
|
|
+ e2 = Math.sqrt((a / b) * (a / b) - 1);
|
|
|
+ double CosB0 = Math.cos(B0);
|
|
|
+ N = (a * a / b) / Math.sqrt(1 + e2 * e2 * CosB0 * CosB0);
|
|
|
+ K = N * CosB0;
|
|
|
+
|
|
|
+ double Pi = Math.PI;
|
|
|
+ double SinB = Math.sin(lat);
|
|
|
+
|
|
|
+ double tan = Math.tan(Pi / 4 + lat / 2);
|
|
|
+ double E2 = Math.pow((1 - e * SinB) / (1 + e * SinB), e / 2);
|
|
|
+ double xx = tan * E2;
|
|
|
+
|
|
|
+ double xc = K * Math.log(xx);
|
|
|
+ double yc = K * lon;
|
|
|
+
|
|
|
+ double[] result = new double[2];
|
|
|
+ result[0] = (int) xc;
|
|
|
+ result[1] = (int) yc;
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double[] xy2normalxy(double x, double y, double angle) {
|
|
|
+
|
|
|
+ double shouGangAngle = Math.toRadians(angle);
|
|
|
+ double x0,y0;
|
|
|
+
|
|
|
+ x0 = x * Math.cos(shouGangAngle) + y * Math.sin(shouGangAngle);
|
|
|
+ y0 = y * Math.cos(shouGangAngle) - x * Math.sin(shouGangAngle);
|
|
|
+
|
|
|
+
|
|
|
+ double[] result = new double[2];
|
|
|
+ result[0] = (int) x0;
|
|
|
+ result[1] = (int) y0;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double[] normalxyShiftToxy(double x, double y, double xShift, double yShift){
|
|
|
+
|
|
|
+ double[] shiftedxy = new double[2];
|
|
|
+ shiftedxy[0] = x - xShift;
|
|
|
+ shiftedxy[1] = y - yShift;
|
|
|
+ return shiftedxy;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static double[] xyShiftToNormalxy(double x, double y, double xShift, double yShift){
|
|
|
+
|
|
|
+ double[] shiftedxy = new double[2];
|
|
|
+ shiftedxy[0] = x + xShift;
|
|
|
+ shiftedxy[1] = y + yShift;
|
|
|
+ return shiftedxy;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static double[] normalxy2xy(double x, double y, double angle){
|
|
|
+
|
|
|
+ double ShouGangAngle = Math.toRadians(angle);
|
|
|
+ double x0,y0;
|
|
|
+ x0 = x * Math.cos(ShouGangAngle) - y * Math.sin(ShouGangAngle);
|
|
|
+ y0 = y * Math.cos(ShouGangAngle) + x * Math.sin(ShouGangAngle);
|
|
|
+
|
|
|
+ double[] result = new double[2];
|
|
|
+ result[0] = (int) x0;
|
|
|
+ result[1] = (int) y0;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static double[] xy2MCT84Bl(double x, double y){
|
|
|
+
|
|
|
+ double B0 = 30 * Math.PI / 180;
|
|
|
+
|
|
|
+ double N = 0, e = 0, a = 0, b = 0, e2 = 0, K = 0;
|
|
|
+ a = 6378137;
|
|
|
+ b = 6356752.3142;
|
|
|
+ e = Math.sqrt(1 - (b / a) * (b / a));
|
|
|
+ e2 = Math.sqrt((a / b) * (a / b) - 1);
|
|
|
+ double CosB0 = Math.cos(B0);
|
|
|
+ N = (a * a / b) / Math.sqrt(1 + e2 * e2 * CosB0 * CosB0);
|
|
|
+ K = N * CosB0;
|
|
|
+ double Pi = Math.PI;
|
|
|
+
|
|
|
+
|
|
|
+ double[] result = new double[2];
|
|
|
+ result[0] = y*180 /(K*Math.PI);
|
|
|
+
|
|
|
+
|
|
|
+ result[1] = 0;
|
|
|
+ int iterativeTimes = 100;
|
|
|
+ double SinB = 0;
|
|
|
+ for (int i = 0; i <iterativeTimes ; i++) {
|
|
|
+ result[1] = Math.PI/2 - 2*Math.atan(Math.pow(Math.E, -x / K)*Math.pow(Math.E,(e/2)*Math.log((1 - e * SinB) / (1 + e * SinB))));
|
|
|
+ SinB = Math.sin(result[1]);
|
|
|
+ }
|
|
|
+ result[1] = result[1]*180/Math.PI;
|
|
|
+
|
|
|
+ double[] resultLatLon = new double[2];
|
|
|
+ resultLatLon[0] = result[1];
|
|
|
+ resultLatLon[1] = result[0];
|
|
|
+ return resultLatLon;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|