zhitong.yu
2024-10-11 4f58a93c95ff123d51adcb8fa2e521333e8ab022
src/main/java/com/hxzk/controller/SystemController.java
@@ -1,6 +1,10 @@
package com.hxzk.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;
@@ -18,18 +22,20 @@
import java.util.Date;
import java.util.List;
import static cn.hx.tools.dd2ddmm;
@RestController
@RequestMapping("/")
public class SystemController {
    static double e2;
    static double e4;
    static double e6;
    static double E0;
    static double N0;
    static double a = 6378.137;
    static double e = 0.0818192;
    static double k0 = 0.9996;
    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;
@@ -43,7 +49,25 @@
        systemService.updaping(baoliu28);
    }
    @GetMapping({"ddmm2d"})
    public String dfConversion(String df) {
        return tools.ddmm2d(df);
    }
    @GetMapping({"dd2ddmm"})
    public String dudegreeConversion(String du) {
        return tools.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"
@@ -53,6 +77,7 @@
        return formattedDate;
    }
    @RequestMapping(value = {"jingweijuli.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView tojisuan1(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView();
@@ -106,10 +131,40 @@
    @ResponseBody
    @RequestMapping(value = {"jisuanjingwei.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public JSONObject jisuanjingwei(String str) {
    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[] 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();
@@ -124,6 +179,48 @@
    }
    @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) {
@@ -143,21 +240,44 @@
        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[] 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);
@@ -172,59 +292,198 @@
        xy[1] = s * x + c * y;
        return xy;
    }
    public static double[] initiize_ublox_zeropoint(double lat, double lon, double th) {
        double[] xycs = new double[]{ubloxraw2xy(lat, lon)[0], ubloxraw2xy(lat, lon)[1], 0.0, 0.0};
        double th1 = th * Math.PI / 180.0;
        xycs[2] = Math.cos(th1);
        xycs[3] = Math.sin(th1);
    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[] xy=new double[3];
        double lond = ublox_dm2d(lon);
        double latd = ublox_dm2d(lat);
        double[] dxy = utm(latd, lond);
        xy[0] = dxy[0] * 1000.0;
        xy[1] = dxy[1] * 1000.0;
        xy[2] = dxy[2];
        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.0);
        double d = d0 + (ddmm_dot_m - d0 * 100.0) / 60.0;
        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.0;
        if (zonenum1 > 0.0) {
            zonenum1 = Math.floor(zonenum1);
        } else {
            zonenum1 = Math.ceil(zonenum1);
    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.0;
        double lambda0 = ((Zonenum - 1.0) * 6.0 - 180.0 + 3.0) * Math.PI / 180.0;
        double phi = lat * Math.PI / 180.0;
        double lambda = lon * Math.PI / 180.0;
        double v = 1.0 / Math.sqrt(1.0 - e2 * Math.pow(Math.sin(phi), 2.0));
        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.0 - e2);
        double C2 = C * C;
        double s = (1.0 - e2 / 4.0 - 3.0 * e4 / 64.0 - 5.0 * e6 / 256.0) * phi - (3.0 * e2 / 8.0 + 3.0 * e4 / 32.0 + 45.0 * e6 / 1024.0) * Math.sin(2.0 * phi) + (15.0 * e4 / 256.0 + 45.0 * e6 / 1024.0) * Math.sin(4.0 * phi) - 35.0 * e6 / 3072.0 * Math.sin(6.0 * phi);
        dxy[0] = E0 + k0 * a * v * (A + (1.0 - T + C) * A3 / 6.0 + (5.0 - 18.0 * T + T2) * A5 / 120.0);
        dxy[1] = N0 + k0 * a * (s + v * Math.tan(phi) * (A2 / 2.0 + (5.0 - T + 9.0 * C + 4.0 * C2) * A4 / 24.0 + (61.0 - 58.0 * T + T2) * A6 / 720.0));
        dxy[2] = Zonenum;
        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;
    }
}