-
Notifications
You must be signed in to change notification settings - Fork 19
/
Converter.java
350 lines (329 loc) · 10.6 KB
/
Converter.java
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package Algorithm.Coords;
import java.util.Date;
import Algorithm.Coords.Point;
public class Converter
{
Converter me ;
double casm_rr = 0;
double casm_t1 = 0;
double casm_t2 = 0;
double casm_x1 = 0;
double casm_y1 = 0;
double casm_x2 = 0;
double casm_y2 = 0;
double casm_f = 0;
public Converter()
{
this.me = this;
this.casm_rr = 0;
this.casm_t1 = 0;
this.casm_t2 = 0;
this.casm_x1 = 0;
this.casm_y1 = 0;
this.casm_x2 = 0;
this.casm_y2 = 0;
this.casm_f = 0;
}
protected double yj_sin2(double x)
{
double tt;
double ss;
double ff;
double s2;
int cc;
ff = 0;
if (x < 0)
{
x = -x;
ff = 1;
}
cc = (int)(x / 6.28318530717959);
tt = x - cc * 6.28318530717959;
if (tt > 3.1415926535897932)
{
tt = tt - 3.1415926535897932;
if (ff == 1)
{
ff = 0;
}
else if (ff == 0)
{
ff = 1;
}
}
x = tt;
ss = x;
s2 = x;
tt = tt * tt;
s2 = s2 * tt;
ss = ss - s2 * 0.166666666666667;
s2 = s2 * tt;
ss = ss + s2 * 8.33333333333333E-03;
s2 = s2 * tt;
ss = ss - s2 * 1.98412698412698E-04;
s2 = s2 * tt;
ss = ss + s2 * 2.75573192239859E-06;
s2 = s2 * tt;
ss = ss - s2 * 2.50521083854417E-08;
if (ff == 1)
{
ss = -ss;
}
return ss;
}
protected double Transform_yj5(double x, double y)
{
double tt;
tt = 300 + 1 * x + 2 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.sqrt(x * x));
tt = tt + (20 * me.yj_sin2(18.849555921538764 * x) + 20 * me.yj_sin2(6.283185307179588 * x)) * 0.6667;
tt = tt + (20 * me.yj_sin2(3.141592653589794 * x) + 40 * me.yj_sin2(1.047197551196598 * x)) * 0.6667;
tt = tt + (150 * me.yj_sin2(0.2617993877991495 * x) + 300 * me.yj_sin2(0.1047197551196598 * x)) * 0.6667;
return tt;
}
protected double Transform_yjy5(double x,double y)
{
double tt;
tt = -100 + 2 * x + 3 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.sqrt(x * x));
tt = tt + (20 * me.yj_sin2(18.849555921538764 * x) + 20 * me.yj_sin2(6.283185307179588 * x)) * 0.6667;
tt = tt + (20 * me.yj_sin2(3.141592653589794 * y) + 40 * me.yj_sin2(1.047197551196598 * y)) * 0.6667;
tt = tt + (160 * me.yj_sin2(0.2617993877991495 * y) + 320 * me.yj_sin2(0.1047197551196598 * y)) * 0.6667;
return tt;
}
protected double Transform_jy5(double x, double xx)
{
double n;
double a;
double e;
a = 6378245;
e = 0.00669342;
n = Math.sqrt(1 - e * me.yj_sin2(x * 0.0174532925199433) * me.yj_sin2(x * 0.0174532925199433));
n = (xx * 180) / (a / n * Math.cos(x * 0.0174532925199433) * 3.1415926);
return n;
}
protected double Transform_jyj5(double x,double yy)
{
double m;
double a;
double e;
double mm;
a = 6378245;
e = 0.00669342;
mm = 1 - e * me.yj_sin2(x * 0.0174532925199433) * me.yj_sin2(x * 0.0174532925199433);
m = (a * (1 - e)) / (mm * Math.sqrt(mm));
return (yy * 180) / (m * 3.1415926);
}
protected int r_yj()
{
int casm_a = 314159269;
int casm_c = 453806245;
return 0;
}
protected double random_yj()
{
double t;
double casm_a = 314159269;
double casm_c = 453806245;
me.casm_rr = casm_a * me.casm_rr + casm_c;
t = (int)(me.casm_rr / 2);
me.casm_rr = me.casm_rr - t * 2;
me.casm_rr = me.casm_rr / 2;
return (me.casm_rr);
}
protected void IniCasm(double w_time, double w_lng, double w_lat)
{
double tt;
me.casm_t1 = w_time;
me.casm_t2 = w_time;
tt = (int)(w_time / 0.357);
me.casm_rr = w_time - tt * 0.357;
if (w_time == 0)
me.casm_rr = 0.3;
me.casm_x1 = w_lng;
me.casm_y1 = w_lat;
me.casm_x2 = w_lng;
me.casm_y2 = w_lat;
me.casm_f = 3;
}
protected Point wgtochina_lb(int wg_flag,int wg_lng, int wg_lat, int wg_heit, int wg_week, int wg_time)
{
double x_add;
double y_add;
double h_add;
double x_l;
double y_l;
double casm_v;
double t1_t2;
double x1_x2;
double y1_y2;
Point point = null;
if (wg_heit > 5000)
{
return point;
}
x_l = wg_lng;
x_l = x_l / 3686400.0;
y_l = wg_lat;
y_l = y_l / 3686400.0;
if (x_l < 72.004)
{
return point;
}
if (x_l > 137.8347)
{
return point;
}
if (y_l < 0.8293)
{
return point;
}
if (y_l > 55.8271)
{
return point;
}
if (wg_flag == 0)
{
me.IniCasm(wg_time, wg_lng, wg_lat);
point = new Point();
point.setLatitude(wg_lng);
point.setLongitude(wg_lat);
return point;
}
me.casm_t2 = wg_time;
t1_t2 = (me.casm_t2 - me.casm_t1) / 1000.0;
if (t1_t2 <= 0)
{
me.casm_t1 = me.casm_t2;
me.casm_f = me.casm_f + 1;
me.casm_x1 = me.casm_x2;
me.casm_f = me.casm_f + 1;
me.casm_y1 = me.casm_y2;
me.casm_f = me.casm_f + 1;
}
else
{
if (t1_t2 > 120)
{
if (me.casm_f == 3)
{
me.casm_f = 0;
me.casm_x2 = wg_lng;
me.casm_y2 = wg_lat;
x1_x2 = me.casm_x2 - me.casm_x1;
y1_y2 = me.casm_y2 - me.casm_y1;
casm_v = Math.sqrt(x1_x2 * x1_x2 + y1_y2 * y1_y2) / t1_t2;
if (casm_v > 3185)
{
return (point);
}
}
me.casm_t1 = me.casm_t2;
me.casm_f = me.casm_f + 1;
me.casm_x1 = me.casm_x2;
me.casm_f = me.casm_f + 1;
me.casm_y1 = me.casm_y2;
me.casm_f = me.casm_f + 1;
}
}
x_add = me.Transform_yj5(x_l - 105, y_l - 35);
y_add = me.Transform_yjy5(x_l - 105, y_l - 35);
h_add = wg_heit;
x_add = x_add + h_add * 0.001 + me.yj_sin2(wg_time * 0.0174532925199433) + me.random_yj();
y_add = y_add + h_add * 0.001 + me.yj_sin2(wg_time * 0.0174532925199433) + me.random_yj();
point = new Point();
point.setX(((x_l + me.Transform_jy5(y_l, x_add)) * 3686400));
point.setY(((y_l + me.Transform_jyj5(y_l, y_add)) * 3686400));
return point;
}
protected boolean isValid(long validdays)
{
//long standand = 1253525356;
long h = 3600;
Date currentTime = new Date();
if(currentTime.getTime()/1000 - 1253525356 >= validdays*24*h)
{
return false;
}
else
{
return true;
}
}
public Point getEncryPoint(double x,double y)
{
Point point = new Point();
double x1, tempx;
double y1, tempy;
x1 = x * 3686400.0;
y1 = y * 3686400.0;
double gpsWeek = 0;
double gpsWeekTime = 0;
double gpsHeight = 0;
point = me.wgtochina_lb(1, (int)(x1), (int)(y1), (int)(gpsHeight), (int)(gpsWeek), (int)(gpsWeekTime));
tempx = point.getX();
tempy = point.getY();
tempx = tempx / 3686400.0;
tempy = tempy / 3686400.0;
point = new Point();
point.setX(tempx);
point.setY(tempy);
return point;
}
protected String getEncryCoord(String coord, boolean flag)
{
if (flag)
{
double x = Double.parseDouble(coord.split(",")[0]);
double y = Double.parseDouble(coord.split(",")[1]);
Point point = new Point();
double x1, tempx;
double y1, tempy;
x1 = x * 3686400.0;
y1 = y * 3686400.0;
int gpsWeek = 0;
int gpsWeekTime = 0;
int gpsHeight = 0;
point = me.wgtochina_lb(1, (int)(x1), (int)(y1), (int)(gpsHeight), (int)(gpsWeek), (int)(gpsWeekTime));
tempx = point.getX();
tempy = point.getY();
tempx = tempx / 3686400.0;
tempy = tempy / 3686400.0;
return tempx + "," + tempy;
}
else
{
return "";
}
}
public static void main(String argv[]) throws Exception
{
Converter c = new Converter();
Point p = c.getEncryPoint(102.702825064591,25.0457617282833);
System.out.println("À¥Ã÷ÊÐ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.485140720179,24.9226075470813);
System.out.println("°²ÄþÊÐ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.795792248383,24.8909889571743);
System.out.println("³Ê¹±ÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.702825064591,25.0457617282833);
System.out.println("³ÇÇø x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(103.180145041594,26.0851335734867);
System.out.println("¶«´¨Çø x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.484333184238,25.238607620033);
System.out.println("¸»ÃñÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.740115855018,25.0118811075002);
System.out.println("¹Ù¶ÉÇø x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.595106736332,24.6679260310969);
System.out.println("½úÄþÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.468291511824,25.5529734769783);
System.out.println("»ȰÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(103.273299939618,24.7568405347061);
System.out.println("ʯÁÖÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(103.041508523306,25.3310846069293);
System.out.println("áÔÃ÷ÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(103.151790850516,25.3343405555925);
System.out.println("Ñ°µéÏØ x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(102.65842000874,25.0390786264324);
System.out.println("Î÷ɽÇø x:"+p.x+" y:"+p.y);
p = c.getEncryPoint(103.146517127597,24.9222445338786);
System.out.println("ÒËÁ¼ÏØ x:"+p.x+" y:"+p.y);
}
}