zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package urt;
 
import java.text.DecimalFormat;
 
public class xytoutm {
 
    static DecimalFormat df = new DecimalFormat("0.0000000");
 
    /**½«dx,dyתΪ¾­Î³¶È¸ß³Ì·µ»Ødouble[]·µ»ØµÄ½á¹ûÊǶȷָñʽµÄ
     * a[0]¾­¶È¶È¸ñʽ
     * a[1]ά¶È¶È¸ñʽ
     * a[2]¾­¶È¶È·Ö¸ñʽ
     * a[3]¾­¶È¶È·Ö¸ñʽ*/
    public static String[] xy2jwd(String dx,String dy,double[] xycs) {
        String xy2jwd[]=new String[4];    
        double x=Double.valueOf(dx);
        double y=Double.valueOf(dy);
        x=x/100;
        y=y/100;
        double utme0=xycs[0];
        double utmn0=xycs[1];
        double c=xycs[2];
        double s=xycs[3];
        double f=xycs[5];
        double[] utm = xyutm(x,y,utme0, utmn0,c,s);
        double jwd[]= utm2ll_wgs84(utm[0],utm[1],f);
        xy2jwd[0]=String.valueOf(df.format(jwd[0]));
        xy2jwd[1]=String.valueOf(df.format(jwd[1]));
        jwd[0]=xytognss.ublox_d2dm(jwd[0]);
        jwd[1]=xytognss.ublox_d2dm(jwd[1]);
        xy2jwd[2]=String.valueOf(df.format(jwd[0]));
        xy2jwd[3]=String.valueOf(df.format(jwd[1]));
        return xy2jwd;
    }
 
    /**xÊÇÐèҪת»»µÄ
     * yÐèҪת»»µÄ
     * utme0³õʼ»¯µÄʱºò»ñµÃµÄÊý¾Ý*/
    public static double[] xyutm(double x,double y,double utme0, double utmn0,double c, double s) {
        double[] utm=new double[2];
        double x1, y1, dx, dy, utme, utmn;
        x1=y; y1=x;
        dx = c*x1 + s*y1;
        dy = -s*x1 + c*y1;
        utme = dx + utme0;
        utmn = dy + utmn0;
        utm[0] = utme;
        utm[1] = utmn;
        return utm;
    }
 
    // function [lat,lon]=utm2ll_wgs84(x,y,f)
    public static double[] utm2ll_wgs84(double x,double y,double f) {
        double[] latlon = new double[2];
        double A1 = 6378137.0;
        double F1 = 298.257223563;
 
        // constants
        double D0 = 180/Math.PI;    
        double maxiter = 100;    
        double eps = 1e-11;    
 
        double K0 = 0.9996;                                
        double X0 = 500000;                                
        // double Y0 = 1e7*(f < 0);
        double Y0 = 0;
        if(f < 0){
            Y0 = 1e7;
        }                    
        double P0 = 0;                                        
        double L0 = (6*Math.abs(f) - 183)/D0;                    
        double E1 = Math.sqrt(( A1*A1 - (A1*(1 - 1/F1))*(A1*(1 - 1/F1)))/(A1*A1));    
        double N = K0*A1;
 
        double[] C = coef(E1,0);
        double YS = Y0 - N*(C[0]*P0 + C[1]*Math.sin(2*P0) + C[2]*Math.sin(4*P0) +
                C[3]*Math.sin(6*P0) + C[4]*Math.sin(8*P0));
 
        C = coef(E1,1);
        double zta = (y - YS)/N/C[0];
        double ztb = (x - X0)/N/C[0];
        double L = zta;
        double LS = ztb;
        // for i = 2:5
        for(int i = 2; i < 6; i++)
        {
            double zta_temp = zta*(i-1)*2;
            double ztb_temp = ztb*(i-1)*2;
            L = L - C[i-1]*Math.sin(zta_temp)*Math.cosh(ztb_temp);
            LS = LS - C[i-1]*Math.cos(zta_temp)*Math.sinh(ztb_temp);
        }
 
        double l = L0 + Math.atan(Math.sinh(LS)/Math.cos(L));
        double p = Math.asin(Math.sin(L)/Math.cosh(LS));
 
        L = Math.log(Math.tan(Math.PI/4 + p/2));
 
        p = 2*Math.atan(Math.exp(L)) - Math.PI/2;
        double p0 = 0;
        double n = 0;
        while ((p0==0 || Math.abs(p - p0) > eps) && n < maxiter) {
            p0 = p;
            double es = E1*Math.sin(p0);
            p = 2*Math.atan(Math.pow((1 + es)/(1 - es), E1/2)*Math.exp(L)) - Math.PI/2;
            n = n + 1;
        }
        latlon[0] = p*D0;
        latlon[1] = l*D0;
        return latlon;
    }
 
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // function c = coef(e,m)
    public static double[] coef(double e,int m) {
        double[][] c0;
        double[] c = new double[5];
        // switch m
        // case 0
        if (m==0) {
            c0 = new double[][] {
                {-175.0/16384.0,0.0,   -5/256.0, 0.0,  -3/64.0, 0.0, -1/4.0, 0.0, 1.0},
                {-105/4096.0,   0.0, -45/1024.0, 0.0,  -3/32.0, 0.0, -3/8.0, 0.0, 0.0},
                {525 /16384.0,  0.0,  45/1024.0, 0.0, 15/256.0, 0.0,    0.0, 0.0, 0.0},
                {-175/12288.0,  0.0, -35/3072.0, 0.0,      0.0, 0.0,    0.0, 0.0, 0.0},
                {315 /131072.0, 0.0,        0.0, 0.0,      0.0, 0.0,    0.0, 0.0, 0.0} // 5x9
            };
        }
        else {
            c0 = new double[][] {
                {-175/16384.0,   0.0,   -5/256.0, 0.0,  -3/64.0, 0.0, -1/4.0, 0.0, 1.0},
                {   1/61440.0,   0.0,   7/2048.0, 0.0,   1/48.0, 0.0,  1/8.0, 0.0, 0.0},
                { 59/368640.0,   0.0,   3/1280.0, 0.0,  1/768.0, 0.0,    0.0, 0.0, 0.0},
                { 283/430080.0,  0.0, 17/30720.0, 0.0,      0.0, 0.0,    0.0, 0.0, 0.0},
                {4397/41287680.0, 0.0,       0.0, 0.0,      0.0, 0.0,    0.0, 0.0, 0.0} // 5x9
            };
        }
        for(int i =1; i < 6; i++)
        {
            for(int j =1; j < 10; j++)
            {
                c[i-1] = c[i-1] + c0[i-1][j-1]*Math.pow(e, 9-j);
            }
        }
        return c;
    }
 
 
}