计算经纬度页面后端springboot代码
王飞
2025-01-23 584633e45c9a93119f17fcf93cb1d9de07286ce0
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
package com.jisuan.controller;
 
//import Jama.Matrix;
//import Jama.SingularValueDecomposition;
import cn.hutool.json.JSONObject;
//import cn.hx.tools;
//import com.hxzk.pojo.TbSystem;
//import com.hxzk.pojo.tb_jingwei;
//import com.hxzk.service.SystemService;
import com.jisuan.Jama.Matrix;
import com.jisuan.Jama.SingularValueDecomposition;
import com.jisuan.pojo.tb_jingwei;
import com.jisuan.util.tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
import static com.jisuan.util.tools.dd2ddmm;
 
//import static cn.hx.tools.dd2ddmm;
 
@RestController
@RequestMapping("/")
public class SystemController {
    static     double a=6378.137;//地球半径
    static     double e=0.0818192;//地球曲率
    static     double k0=0.9996;
    static double e2=e*e;//e的平方
    static double e4=e2*e2;//e的4次方
    static double e6=e4*e2;//e的6次方
    static double E0=500;
    static double N0=0;
//    @Autowired
//    SystemService systemService;/
 
//    @GetMapping("findsystem")
//    public List<TbSystem> findsystem(){
//        return systemService.findsystem();
//    }
    //修改大屏默认显示地图
//    @PostMapping("updaping")
//    public void updaping(String baoliu28){
//        systemService.updaping(baoliu28);
//    }
 
    @GetMapping({"ddmm2d"})
    public String dfConversion(String df) {
        return tools.ddmm2d(df);
    }
 
    @GetMapping({"dd2ddmm"})
    public String dudegreeConversion(String du) {
        return dd2ddmm(du);
    }
 
    @GetMapping({"toplane"})
    public String zuobiao(String posPlane, String posPointCloud, String posPointCloudCheck) {
        return toplane(posPlane, posPointCloud, posPointCloudCheck);
    }
 
    @GetMapping({"gnssToxy"})
    public String[] coordinate(String gnssa, String gnssb, String gnsslat, String gnsslog) {
        return tools.gnssToxy(gnssa, gnssb, gnsslat, gnsslog);
    }
    public String gettime(){
        Date now = new Date();
        // 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm"
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        // 格式化日期对象,输出字符串结果
        String formattedDate = sdf.format(now);
        return formattedDate;
    }
 
 
    @RequestMapping(value = {"jingweijuli.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView tojisuan1(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("jisuan1.jsp");
        return modelAndView;
    }
 
 
    @ResponseBody
    @RequestMapping(
            value = {"jisuanjingwei2.do"},
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public JSONObject jisuanjingwei2(String str) {
        JSONObject json = new JSONObject();
        String[] split = str.split(";");
        double[] sy = gpstodu(split[1], split[0]);
        String str2 = sy[1] + ";" + sy[0];
        json.put("jieguo", str2);
        return json;
    }
 
    @ResponseBody
    @RequestMapping(
            value = {"jisuanjingwei3.do"},
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public JSONObject jisuanjingwei3(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        String qidian = request.getParameter("qidian");
        String zhongdian = request.getParameter("zhongdian");
        String[] qidians = qidian.split(",");
        String[] zhongdians = zhongdian.split(",");
        String str = qidians[2] + ";" + qidians[4] + ";" + zhongdians[2] + ";" + zhongdians[4];
        String disab = disab(str);
        String[] split = str.split(";");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
    }
 
 
 
    @ResponseBody
    @RequestMapping(value = {"jisuanjingwei.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public static JSONObject jisuanjingwei(String str) {
 
//        3954.4464;11618.4476;3954.4464;11624.969
        JSONObject json = new JSONObject();
        String disab = disab(str);
        String[] split = str.split("");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
 
    }
 
    @ResponseBody
    @RequestMapping(
            value = {"jisuanbaowen.do"},
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public static JSONObject jisuanbaowen(String gnggA, String gnggB) {
        String weiduA = gnggA.split(",")[2];
        String jingduA = gnggA.split(",")[4];
        String weiduB = gnggB.split(",")[2];
        String jingduB = gnggB.split(",")[4];
        String str = weiduA + ";" + jingduA + ";" + weiduB + ";" + jingduB;
        JSONObject json = new JSONObject();
        String disab = disab(str);
        String[] split = str.split("");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
    }
 
 
    @ResponseBody
    @RequestMapping(value = {"jisuandubaowen.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public static JSONObject jisuandubaowen(String dugnggA ,String dugnggB) {
        String weiduA =   dd2ddmm(dugnggA.split(";")[0]);
        String jingduA =   dd2ddmm(dugnggA.split(";")[1]);
        String weiduB =   dd2ddmm(dugnggB.split(";")[0]);
        String jingduB =   dd2ddmm(dugnggB.split(";")[1]);
 
//        String weiduA = gnggA.split(",")[2];
//        String jingduA = gnggA.split(",")[4];
//        String weiduB = gnggB.split(",")[2];
//        String jingduB = gnggB.split(",")[4];
        String str = weiduA + ";" + jingduA + ";" + weiduB + ";" + jingduB;
        JSONObject json = new JSONObject();
        String disab = disab(str);
        String[] split = str.split("");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
    }
 
 
    @PostMapping({"HouTai"})
    public ModelAndView HouTai(String username) {
        ModelAndView modelAndView = new ModelAndView();
        if (username != null) {
            modelAndView.setViewName("/HouTai/HouTai.jsp");
        } else {
            modelAndView.setViewName("/index.jsp");
        }
 
        return modelAndView;
    }
 
 
 
    public static String todufen(String Du, String Fen, String Miao) {
        Float strDu = Float.valueOf(Du);
        Float strFen = Float.valueOf(Fen) / 60.0F;
        Float strMiao = Float.valueOf(Miao) / 60.0F;
        Float dufenmiao = strDu + strFen + strMiao;
        String format = String.format("%.6f", dufenmiao);
        return format;
    }
    public static double[] gpstodu(String gps_weidu, String gps_jingdu) {
        double[] a = new double[]{0.0, 0.0};
        String weidu = todufen(gps_weidu.substring(0, 2), gps_weidu.substring(2, 4), gps_weidu.substring(4));
        String jingdu = todufen(gps_jingdu.substring(0, 3), gps_jingdu.substring(3, 5), gps_jingdu.substring(5));
        a[0] = Double.parseDouble(weidu);
        a[1] = Double.parseDouble(jingdu);
        return a;
    }
 
 
    public static String disab(String jwd) {
        System.out.println("打印数据============》》》》》》》》》》");
        DecimalFormat df = new DecimalFormat("0.00");
        String[] bb = jwd.split(";");
        double jd0 = Double.parseDouble(bb[1]);
        double wd0 = Double.parseDouble(bb[0]);
        double jd1 = Double.parseDouble(bb[3]);
        double wd1 = Double.parseDouble(bb[2]);
//        double[] a = run_gps2xyurt(wd0, jd0, wd1, jd1);
//        double disa = a[0] * a[0] + a[1] * a[1];
//        double dis = Math.sqrt(Math.abs(disa)) * 100.0;
//        String temp = df.format(dis);
 
//        double num1 = Double.parseDouble(jd0);
//        double num2 = Double.parseDouble(gnssb);
//        double num3 = Double.parseDouble(gnsslat);
//        double num4 = Double.parseDouble(gnsslog);
        String temp = distance2(jd0,wd0,jd1,wd1);
        System.out.println(jwd + "的距离是:" + temp);
//        return distance2(jd0,wd0,jd1,wd1);
        return temp;
    }
 
    // public static String disab(String jwd) {
    //     DecimalFormat df = new DecimalFormat("0.00");
    //     String[] bb = jwd.split(";");
    //     double jd0 = Double.parseDouble(bb[1]);
    //     double wd0 = Double.parseDouble(bb[0]);
    //     double jd1 = Double.parseDouble(bb[3]);
    //     double wd1 = Double.parseDouble(bb[2]);
    //     double[] a = run_gps2xyurt(wd0, jd0, wd1, jd1);
    //     double disa = a[0] * a[0] + a[1] * a[1];
    //     double dis = Math.sqrt(Math.abs(disa)) * 100.0;
    //     String temp = df.format(dis);
    //     return temp;
    // }
 
    public static double[] run_gps2xyurt(double lat0, double lon0, double lat, double lon) {
        int[] realxy = new int[2];
        double[] xycs = initiize_ublox_zeropoint(lat0, lon0, 0.0);
        double x0 = xycs[0];
        double y0 = xycs[1];
        double c = xycs[2];
        double s = xycs[3];
        double[] xy = new double[2];
        double x = ubloxraw2xy(lat, lon)[0] - x0;
        double y = ubloxraw2xy(lat, lon)[1] - y0;
        xy[0] = c * x - s * y;
        xy[1] = s * x + c * y;
        return xy;
    }
    public static String toplane(String posPlane1, String posPointCloud1, String posPointCloudCheck1) {
        double[][] posPlane = string2doubleArr(posPlane1, 1);
        double[][] posPointCloud = string2doubleArr(posPointCloud1, 100);
        double[][] posPointCloudCheck = string2doubleArr(posPointCloudCheck1, 100);
        String returnDate = "";
        double[][] var7 = posPlane;
        int var8 = posPlane.length;
 
        for(int var9 = 0; var9 < var8; ++var9) {
            double[] row = var7[var9];
            row[1] = -row[1];
        }
 
        Matrix A = new Matrix(posPlane);
        Matrix B = new Matrix(posPointCloud);
        Matrix C = new Matrix(posPointCloudCheck);
        Matrix[] matrices = rigidTransform3D(A, B);
        if (matrices == null) {
            return "选点有问题,请重新选点";
        } else {
            Matrix R = matrices[0];
            Matrix T = matrices[1];
            Matrix posPlaneCheckCalc = R.transpose().times(C.transpose().minus(T));
            Matrix transpose = posPlaneCheckCalc.transpose();
            double[][] transposeArray = transpose.getArray();
 
            for(int i = 0; i < transposeArray.length; ++i) {
                for(int j = 0; j < transposeArray[0].length; ++j) {
                    double v = 0.0;
                    if (j == 1) {
                        v = -transposeArray[i][j];
                    } else {
                        v = transposeArray[i][j];
                    }
 
                    returnDate = returnDate + v + ";";
                }
            }
 
            return returnDate;
        }
    }
 
    public static Matrix[] rigidTransform3D(Matrix A, Matrix B) {
        Matrix centroid_A = mean(A);
        Matrix centroid_B = mean(B);
        int N = A.getRowDimension();
        Matrix H = A.minus(repmat(centroid_A, N, 1)).transpose().times(B.minus(repmat(centroid_B, N, 1)));
        SingularValueDecomposition svd = H.svd();
        Matrix U = svd.getU();
        Matrix S = svd.getS();
        Matrix V = svd.getV();
        Matrix R = V.times(U.transpose());
        if (R.det() < 0.0) {
            return null;
        } else {
            Matrix T = R.times(centroid_A.transpose()).times(-1.0).plus(centroid_B.transpose());
            return new Matrix[]{R, T};
        }
    }
 
    private static Matrix mean(Matrix matrix) {
        int m = matrix.getRowDimension();
        int n = matrix.getColumnDimension();
        double[] columnMeans = new double[n];
 
        for(int j = 0; j < n; ++j) {
            for(int i = 0; i < m; ++i) {
                columnMeans[j] += matrix.get(i, j);
            }
 
            columnMeans[j] /= (double)m;
        }
 
        return (new Matrix(columnMeans, n)).transpose();
    }
 
    private static Matrix repmat(Matrix matrix, int N, int M) {
        Matrix result = new Matrix(N, M * matrix.getColumnDimension());
 
        for(int i = 0; i < N; ++i) {
            result.setMatrix(i, i, 0, matrix.getColumnDimension() - 1, matrix);
        }
 
        return result;
    }
 
    private static double[][] string2doubleArr(String input, int num) {
        String[] rows = input.split(";");
        double[][] result = new double[rows.length][];
 
        for(int i = 0; i < rows.length; ++i) {
            String[] columns = rows[i].trim().split(",\\s*");
            result[i] = new double[columns.length];
 
            for(int j = 0; j < columns.length; ++j) {
                result[i][j] = Double.parseDouble(columns[j]) * (double)num;
            }
        }
 
        return result;
    }
 
    public static String distance2(double lon_y0, double lat_x0, double lon, double lat) {
        System.out.println(lon_y0);
        System.out.println(lat_x0);
        System.out.println(lon);
        System.out.println(lat);
        double[] xycs = initiize_ublox_zeropoint(lat_x0, lon_y0, 0.0);
        double x0 = xycs[0];
        double y0 = xycs[1];
        double c = xycs[2];
        double s = xycs[3];
        double[] xy = new double[2];
        double x = ubloxraw2xy(lat, lon)[0] - x0;
        double y = ubloxraw2xy(lat, lon)[1] - y0;
        xy[0] = c * x - s * y;
        xy[1] = s * x + c * y;
        double disd = Math.sqrt(xy[0] * xy[0] + xy[1] * xy[1]) * 100.0;
        return disd + "";
    }
    /**初始化原点位置和方向
     * 输出原点以米为单位的xy坐标, cos值, sin值*/
    public static double[] initiize_ublox_zeropoint(double lat, double lon, double th){
        double[] xycs=new double[4];
        xycs[0]=ubloxraw2xy(lat,lon)[0];
        xycs[1]=ubloxraw2xy(lat,lon)[1];
        double th1=th*Math.PI/180;//x轴与正北方向夹角th(单位是度)
        xycs[2]=Math.cos(th1);
        xycs[3]=Math.sin(th1);
        return xycs;
    }
 
    /**输入ublox的度分经纬度,输出xy,单位米*/
    public static double[] ubloxraw2xy(double lat, double lon) {
        double[] xy=new double[3];
        double lond = ublox_dm2d(lon);
        double latd = ublox_dm2d(lat);
        double[] dxy = utm(latd, lond);
        xy[0]= dxy[0]* 1000;
        xy[1]= dxy[1]* 1000;
        xy[2]= dxy[2];
        return xy;
 
    }
    public static double ublox_dm2d(double ddmm_dot_m) {
        double d0=Math.floor(ddmm_dot_m/100);//取整
        double d=d0+(ddmm_dot_m-d0*100)/60;
        return d;
    }
    public static double[] utm(double lat,double lon) {
        double[] dxy=new double[3];
 
        double zonenum1=lon/6;
        //floor是地板的意思,表示向下取整
        if(zonenum1>0) {
            zonenum1=Math.floor(zonenum1);
        }else {//向上取整
            zonenum1=Math.ceil(zonenum1);//向上取整
        }
 
        double Zonenum=zonenum1+31;
 
        double lambda0=((Zonenum-1)*6-180+3)*(Math.PI)/180;
 
        double phi=lat*(Math.PI)/180;
 
        double lambda=lon*(Math.PI)/180;
 
        double v=1/Math.sqrt((1-e2*Math.pow(Math.sin(phi),2)));
 
        double A=(lambda-lambda0)* Math.cos(phi);
        double A2=A*A;
        double A3=A2*A;
        double A4=A3*A;
        double A5=A4*A;
        double A6=A5*A;
 
        double T=Math.tan(phi)* Math.tan(phi);
        double T2=T*T;
 
        double C=e2* Math.cos(phi)* Math.cos(phi)/(1-e2);
        double C2=C*C;
 
        double s=(1-e2/4-3*e4/64-5*e6/256)* phi-
                (3*e2/8+3*e4/32+45*e6/1024)* Math.sin(2*phi)+
                (15*e4/256+45*e6/1024)* Math.sin(4* phi)-35*e6/3072* Math.sin(6*phi);
 
        dxy[0]=E0+k0*a*v*(A+(1-T+C)*A3/6+(5-18*T+T2)*A5/120);
 
        dxy[1]=N0+k0*a*(s+v* Math.tan(phi)*(A2/2+(5-T+9*C+4*C2)*A4/24+(61-58*T+T2)*A6/720));
        dxy[2]=Zonenum;
        return dxy;
    }
}