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 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; } }