Browse Source

输出结果到文件

16s01 4 years ago
parent
commit
02468cf1ac

+ 109 - 11
src/test/Cal.java

@@ -13,6 +13,8 @@ public class Cal {
 
     ArrayList<OccupyPerX> occupyPerXArrayList = new ArrayList<>();//占用情况
 
+    Integer numOfGaps = 100;
+
     public ArrayList<Point> calShape() throws SQLException, FileNotFoundException {
 
         GetPoints getPoints = new GetPoints();
@@ -32,6 +34,9 @@ public class Cal {
         ArrayList<Double> xIndexCorList = split.xIndexCorList;//格点横坐标List
         ArrayList<Double> yIndexCorList = split.yIndexCorList;//格点纵坐标List
         WholeIndexOccupy wholeIndexOccupy = split.wholeIndexOccupy;//初始垛位的占用情况
+//        ArrayList<Point> occupyShapeList = wholeIndexOccupy.getOccupyPointsArrayList();//坐标形式的初始形状
+
+        System.out.println(occupyPerXArrayList);
 
 //        wholeIndexOccupy.printOccupy();
 
@@ -44,6 +49,7 @@ public class Cal {
         Double maxY = yIndexCorList.get(yIndexCorList.size() - 1);
 
         wholeIndexOccupy.printOccupy(minX,minY,xGap,yGap);
+        ArrayList<Point> occupyShapeList = wholeIndexOccupy.getOccupyPointsArrayList();//坐标形式的初始形状
 
 
         ArrayList<Point> pointAfterExclude = new ArrayList<>();//过滤后的所有点的坐标
@@ -93,7 +99,7 @@ public class Cal {
             Integer xIndex = split.identifyXIndex(x);
             Integer yIndex = split.identifyYIndex(y);
 
-            if (yIndex < 100 && yIndex >=0){
+            if (yIndex < numOfGaps && yIndex >=0){
 
                 ArrayList<Integer> arrayList = occupyList.get(xIndex);
                 arrayList.set(yIndex,0);
@@ -170,30 +176,68 @@ public class Cal {
         ArrayList<Point> shape = new ArrayList<>();
         for (int i = 0 ; i < occupyPerXArrayList.size();i++){
 
+//            OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
+//            Double xCor = minX + i * xGap + 0.5 * xGap;
+//            Integer yIndex = occupyPerX.maxYIndex;
+//            Double yCor = minY + yIndex * yGap + 0.5 * yGap;
+//            Point point = new Point();
+//            point.setColX(xCor);
+//            point.setColY(yCor);
+
+
+
             OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
-            Double xCor = minX + i * xGap + 0.5 * xGap;
+            Double xCor1 = minX + i * xGap;
+            Double xCor2 = minX + i * xGap + xGap;
             Integer yIndex = occupyPerX.maxYIndex;
             Double yCor = minY + yIndex * yGap + 0.5 * yGap;
-            Point point = new Point();
-            point.setColX(xCor);
-            point.setColY(yCor);
-            shape.add(point);
+
+            Point point1 = new Point();
+            point1.setColX(xCor1);
+            point1.setColY(yCor);
+
+            Point point2 = new Point();
+            point2.setColX(xCor2);
+            point2.setColY(yCor);
+
+
+            shape.add(point1);
+            shape.add(point2);
         }
 
         for (int i = (occupyPerXArrayList.size() -1) ; i >=0;i--){
 
+//            OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
+//            Double xCor = minX + i * xGap + 0.5 * xGap;
+//            Integer yIndex = occupyPerX.minYIndex;
+//            Double yCor = minY + yIndex * yGap + 0.5 * yGap;
+//            Point point = new Point();
+//            point.setColX(xCor);
+//            point.setColY(yCor);
+//
+//            shape.add(point);
+
             OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
-            Double xCor = minX + i * xGap + 0.5 * xGap;
+            Double xCor1 = minX + i * xGap;
+            Double xCor2 = minX + i * xGap + xGap;
             Integer yIndex = occupyPerX.minYIndex;
             Double yCor = minY + yIndex * yGap + 0.5 * yGap;
-            Point point = new Point();
-            point.setColX(xCor);
-            point.setColY(yCor);
 
-            shape.add(point);
+            Point point1 = new Point();
+            point1.setColX(xCor1);
+            point1.setColY(yCor);
+
+            Point point2 = new Point();
+            point2.setColX(xCor2);
+            point2.setColY(yCor);
+
+            shape.add(point2);
+            shape.add(point1);
+
         }
 
         shape.add(shape.get(0));
+        System.out.println(shape.size() + ")))))))))))))))000");
 
 
 //        System.out.println(shape.size());
@@ -205,6 +249,10 @@ public class Cal {
 //        }
 
         operateFile.printPoint("Y:\\changed.txt",shape);
+
+        ArrayList<Point> afterAdjustPointsList = adjustShape(occupyShapeList,shape,5);
+
+        operateFile.printPoint("Y:\\adjustchanged.txt",afterAdjustPointsList);
         return shape;
 
 
@@ -272,4 +320,54 @@ public class Cal {
 
     }
 
+
+    public ArrayList<Point> adjustShape(ArrayList<Point> initialShapeList,ArrayList<Point> changedShapeList,Integer adjustSize){
+
+
+        Integer size = initialShapeList.size() - 1;
+
+        System.out.println(size + "size");
+
+        ArrayList<Point> afterAdjustPointsList = new ArrayList<>();
+
+        Integer round = size / adjustSize;
+
+        System.out.println(round + "round");
+
+        for (int i = 0; i < round ;i++){
+
+            Integer indexBegin = i * adjustSize;
+            Integer indexEnd = indexBegin + adjustSize;
+
+            Double avgDec = 0.0;
+            for (int j = indexBegin;j < indexEnd; j++){
+                Point iniPoint = initialShapeList.get(j);
+                Point chaPoint = changedShapeList.get(j);
+                avgDec = avgDec + chaPoint.getColY() - iniPoint.getColY();
+            }
+            avgDec = avgDec / adjustSize;
+            System.out.println(avgDec + " avgdec");
+
+            for (int j = indexBegin ; j < indexEnd;j++){
+
+//                Point chaPoint = changedShapeList.get(j);
+                Point intPoint = initialShapeList.get(j);
+                Point adjustPoint = new Point();
+                adjustPoint.setColX(intPoint.getColX());
+                adjustPoint.setColY(intPoint.getColY() + avgDec);
+
+                afterAdjustPointsList.add(adjustPoint);
+            }
+            //后面扩充不整除的情况
+        }
+
+        afterAdjustPointsList.add(afterAdjustPointsList.get(0));
+
+
+
+        return afterAdjustPointsList;
+
+
+    }
+
 }

+ 163 - 0
src/test/GPS/GpsConvertMethod.java

@@ -0,0 +1,163 @@
+package test.GPS;
+
+/**
+ * @创建人 ccj
+ * @创建时间 2020/7/25
+ * @描述
+ */
+public class GpsConvertMethod {
+
+    //首钢的角度为55.5度
+    //首钢 xShift 值为11789993,yShift 值为3128152
+
+    public  double[] coordinatexy;
+
+    public  double[] coordinatelb;
+
+    public GpsConvertMethod(String name, double x, double y,  double angle, double xShift, double yShift) {
+
+        if(name == "MCT2XY"){
+
+
+            double[]  xy = new double[2];
+            xy =  MCT84Bl2xy(x,y);
+            double[] normalxy = new double[2];
+            normalxy = xy2normalxy(xy[0],xy[1], angle);
+            coordinatexy = new double[2];
+            coordinatexy = normalxyShiftToxy(normalxy[0],normalxy[1],xShift,yShift);
+
+        }
+        if(name == "XY2MCT"){
+
+
+            double[]  normalxy = new double[2];
+            normalxy =  xyShiftToNormalxy(x,y,xShift,yShift);
+            double[] xy = new double[2];
+            xy = normalxy2xy(normalxy[0],normalxy[1], angle);
+            coordinatelb = new double[2];
+            coordinatelb = xy2MCT84Bl(xy[0],xy[1]);
+
+        }
+
+
+    }
+
+    public  static double[] MCT84Bl2xy(double lat, double lon) { //墨卡托投影转换平面坐标
+        lon = lon * Math.PI / 180; //角度转弧度
+        lat = lat * Math.PI / 180; //角度转弧度
+
+        double B0 = 30 * Math.PI / 180; //角度转弧度
+
+        double N = 0, e = 0, a = 0, b = 0, e2 = 0, K = 0;
+        a = 6378137;
+        b = 6356752.3142;
+        e = Math.sqrt(1 - (b / a) * (b / a));//椭圆的第一偏心率,扁率
+        e2 = Math.sqrt((a / b) * (a / b) - 1); //椭圆的第二偏心率, 扁率
+        double CosB0 = Math.cos(B0);
+        N = (a * a / b) / Math.sqrt(1 + e2 * e2 * CosB0 * CosB0);
+        K = N * CosB0;
+
+        double Pi = Math.PI;
+        double SinB = Math.sin(lat);
+
+        double tan = Math.tan(Pi / 4 + lat / 2);//墨卡托投影的计算中间值
+        double E2 = Math.pow((1 - e * SinB) / (1 + e * SinB), e / 2);
+        double xx = tan * E2;
+
+        double xc = K * Math.log(xx);
+        double yc = K * lon;
+
+        double[] result = new double[2];
+        result[0] = (int) xc;
+        result[1] = (int) yc;
+        return result;
+
+
+    }
+
+    public  static double[] xy2normalxy(double x, double y, double angle) {
+        //首钢的角度为55.5度
+        double shouGangAngle = Math.toRadians(angle);
+        double x0,y0;
+
+        x0 = x * Math.cos(shouGangAngle) +  y * Math.sin(shouGangAngle);
+        y0 = y * Math.cos(shouGangAngle) -  x * Math.sin(shouGangAngle);
+
+
+        double[] result = new double[2];
+        result[0] = (int) x0;
+        result[1] = (int) y0;
+        return result;
+    }
+
+    public static double[] normalxyShiftToxy(double x, double y, double xShift, double yShift){
+        //首钢 xShift 值为11789993,yShift 值为3128152
+        double[] shiftedxy = new double[2];
+        shiftedxy[0] = x - xShift;
+        shiftedxy[1] = y - yShift;
+        return  shiftedxy;
+    }
+
+
+    public static double[] xyShiftToNormalxy(double x, double y, double xShift, double yShift){
+        //首钢 xShift 值为11789993,yShift 值为3128152
+        double[] shiftedxy = new double[2];
+        shiftedxy[0] = x + xShift;
+        shiftedxy[1] = y + yShift;
+        return  shiftedxy;
+    }
+
+
+    public static double[] normalxy2xy(double x, double y, double angle){
+        //首钢的角度为55.5度
+        double ShouGangAngle = Math.toRadians(angle);
+        double x0,y0;
+        x0 = x * Math.cos(ShouGangAngle) -  y * Math.sin(ShouGangAngle);
+        y0 = y * Math.cos(ShouGangAngle) +  x * Math.sin(ShouGangAngle);
+
+        double[] result = new double[2];
+        result[0] = (int) x0;
+        result[1] = (int) y0;
+        return result;
+    }
+
+
+
+    public static  double[] xy2MCT84Bl(double x, double y){
+
+        double B0 = 30 * Math.PI / 180; //角度转弧度
+
+        double N = 0, e = 0, a = 0, b = 0, e2 = 0, K = 0;
+        a = 6378137;
+        b = 6356752.3142;
+        e = Math.sqrt(1 - (b / a) * (b / a));//椭圆的第一偏心率,扁率
+        e2 = Math.sqrt((a / b) * (a / b) - 1); //椭圆的第二偏心率, 扁率
+        double CosB0 = Math.cos(B0);
+        N = (a * a / b) / Math.sqrt(1 + e2 * e2 * CosB0 * CosB0);
+        K = N * CosB0;
+        double Pi = Math.PI;
+
+
+        double[] result = new double[2];
+        result[0] = y*180 /(K*Math.PI);
+        //这里的坐标需要迭代才能求出
+        //初始值,迭代次数
+        result[1] = 0;
+        int iterativeTimes = 100;
+        double SinB = 0;
+        for (int i = 0; i <iterativeTimes ; i++) {
+            result[1] = Math.PI/2 - 2*Math.atan(Math.pow(Math.E, -x / K)*Math.pow(Math.E,(e/2)*Math.log((1 - e * SinB) / (1 + e * SinB))));
+            SinB = Math.sin(result[1]);
+        }
+        result[1] = result[1]*180/Math.PI;
+
+        double[] resultLatLon = new double[2];
+        resultLatLon[0] = result[1];
+        resultLatLon[1] = result[0];
+        return resultLatLon;
+
+    }
+
+
+
+}

+ 35 - 4
src/test/GetPoints.java

@@ -3,10 +3,12 @@ package test;
 
 import test.entity.Point;
 
+import java.io.FileNotFoundException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Map;
 
 //暂时先自己写connection从数据库中获取
 
@@ -29,7 +31,7 @@ public class GetPoints {
 
     }
 
-    public void getPoints() throws SQLException {
+    public void getPoints() throws SQLException, FileNotFoundException {
 
 
 
@@ -72,15 +74,19 @@ public class GetPoints {
 //        A08
         String realShapeBeginTime = "2020-07-22 14:58:00.000000";
         String realShapeEndTime = "2020-07-22 15:04:00.000000";
-
+//
         String allPointsBeginTime = "2020-07-24 20:17:00.000000";
         String allPointsEndTime = "2020-07-25 07:36:00.000000";
 
         String sql1 = "select GPS_LAT,GPS_LON from T_LOC_APP_CLIENT_STATUS@DBLINKLOC WHERE CLIENT_RECORD_TIME between to_timestamp('" + realShapeBeginTime  + "', 'yyyy-mm-dd hh24:mi:ss.ff') and to_timestamp('" + realShapeEndTime + "', 'yyyy-mm-dd hh24:mi:ss.ff')";
         String sql2 = "select GPS_LAT,GPS_LON from T_LOC_APP_CLIENT_STATUS@DBLINKLOC WHERE CLIENT_RECORD_TIME between to_timestamp('" + allPointsBeginTime  + "', 'yyyy-mm-dd hh24:mi:ss.ff') and to_timestamp('" + allPointsEndTime + "', 'yyyy-mm-dd hh24:mi:ss.ff')";
 
-        realShapePoints = buildPoints(sql1);
-        allPoints = buildPoints(sql2);
+//        realShapePoints = buildPoints(sql1);
+//        allPoints = buildPoints(sql2);
+        realShapePoints = buildPointsFromFile("Y:\\programresult\\dbdiff\\points\\shape.txt");
+        allPoints = buildPointsFromFile("Y:\\programresult\\dbdiff\\points\\allpoints.txt");
+
+
 
 //        Connection
 
@@ -117,5 +123,30 @@ public class GetPoints {
     }
 
 
+    public ArrayList<Point> buildPointsFromFile(String filePath) throws FileNotFoundException {
+
+        ArrayList<Point> pointArrayList = new ArrayList<>();
+        OperateFile operateFile = new OperateFile();
+        ArrayList<Map> pointsMapList = operateFile.readPoints(filePath);
+
+        for (int i = 0 ; i < pointsMapList.size();i++){
+
+            Map mapTemp = pointsMapList.get(i);
+            Double lat = (Double) mapTemp.get("lat");
+            Double lon = (Double) mapTemp.get("lon");
+            GpsExchange gpsExchange = new GpsExchange();
+            Point point = gpsExchange.gpsToPoints(lat,lon);
+            pointArrayList.add(point);
+
+        }
+
+
+
+        return pointArrayList;
+
+
+    }
+
+
 
 }

+ 9 - 2
src/test/GpsExchange.java

@@ -1,6 +1,7 @@
 package test;
 
 //import test.entity.GpsCor;
+import test.GPS.GpsConvertMethod;
 import test.entity.Point;
 
 public class GpsExchange {
@@ -14,8 +15,14 @@ public class GpsExchange {
         Double x = array[0];
         Double y = array[1];
 
-        point.setColX(x);
-        point.setColY(y);
+        GpsConvertMethod gpsConvertMethod = new GpsConvertMethod("MCT2XY",lat,lon,55.5, 11789993,3128152);
+        double[] array2 = gpsConvertMethod.coordinatexy;
+
+
+        point.setColX(array2[0]);
+        point.setColY(array2[1]);
+//        point.setColX(x);
+//        point.setColY(y);
 
         return point;
 

+ 39 - 0
src/test/OperateFile.java

@@ -6,6 +6,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Scanner;
 
 public class OperateFile {
@@ -37,6 +39,43 @@ public class OperateFile {
 
     }
 
+    public ArrayList<Map> readPoints(String filePath) throws FileNotFoundException {
+
+
+        File file = new File(filePath);
+
+        System.out.println(filePath);
+
+        Scanner input = new Scanner(file);
+
+        ArrayList<Map> dataArrayList = new ArrayList<>();
+
+        while (input.hasNext()){
+
+            String latStr = input.next();
+            String lonStr = input.next();
+            System.out.println(latStr);
+            System.out.println(lonStr);
+
+            Double lat = Double.parseDouble(latStr);
+            Double lon = Double.parseDouble(lonStr);
+
+            Map mapTemp = new HashMap();
+            mapTemp.put("lat",lat);
+            mapTemp.put("lon",lon);
+            dataArrayList.add(mapTemp);
+
+        }
+
+        input.close();
+
+        return dataArrayList;
+
+    }
+
+
+
+
 
     public ArrayList readFileStream(String filePath) throws FileNotFoundException {
 

+ 14 - 14
src/test/Split.java

@@ -444,16 +444,16 @@ public class Split {
         Double xIndexTemp = (pointX - minX) / xGap;
         Double yIndexTemp = (pointY - minY) / yGap;
 
-        if (xIndexTemp > 100){
-
-            System.out.println(1111111111);
-            System.out.println("x is :" + pointX);
-            System.out.println("minx is : " + minX);
-            System.out.println("xgap is :" + xGap);
-            System.out.println("x - minx = " + (pointX - minX));
-            System.out.println("result is " + (pointX - minX) / xGap);
-
-        }
+//        if (xIndexTemp > 100){
+//
+//            System.out.println(1111111111);
+//            System.out.println("x is :" + pointX);
+//            System.out.println("minx is : " + minX);
+//            System.out.println("xgap is :" + xGap);
+//            System.out.println("x - minx = " + (pointX - minX));
+//            System.out.println("result is " + (pointX - minX) / xGap);
+//
+//        }
 
 //        System.out.println("pointx: " + pointX +" - " +"minx: " + minX + " = " + (pointX - minX));
 //        System.out.println("(pointX - minX) / xGap: " + xIndexTemp);
@@ -470,13 +470,13 @@ public class Split {
 
         Index index = new Index();
 
-        if (xIndex == 100){
+        if (xIndex == numOfGaps){
 
             xIndex = xIndex -1;
 
         }
 
-        if (yIndex == 100){
+        if (yIndex == numOfGaps){
 
             yIndex = yIndex -1;
 
@@ -511,9 +511,9 @@ public class Split {
         Double xIndexTemp = (xCor - xMin)/xGap;
         Integer xIndex = xIndexTemp.intValue();
 
-        if (xIndex >= 100){
+        if (xIndex >= numOfGaps){
 
-            xIndex = 99;
+            xIndex = numOfGaps - 1;
 
         }
 

+ 37 - 10
src/test/entity/WholeIndexOccupy.java

@@ -9,6 +9,8 @@ public class WholeIndexOccupy {
 
     ArrayList<OccupyPerX> occupyPerXArrayList = new ArrayList<>();
 
+    ArrayList<Point> occupyPointsArrayList = new ArrayList<>();
+
     public WholeIndexOccupy(Integer numberOfGaps){
 
         for (int i = 0;i < numberOfGaps;i++){
@@ -22,6 +24,11 @@ public class WholeIndexOccupy {
 
     }
 
+    public ArrayList<Point> getOccupyPointsArrayList(){
+
+        return occupyPointsArrayList;
+    }
+
 
     public void setOccupyPerXArrayList(OccupyPerX occupyPerX,Integer xIndex){
 
@@ -85,13 +92,20 @@ public class WholeIndexOccupy {
             Integer maxYIndex = occupyPerX.getMaxYIndex();
             if (maxYIndex != -1 && minYIndex !=1000){
 
-                Double xCor = minX + i * xGap + 0.5 * xGap;
+//                Double xCor = minX + i * xGap + 0.5 * xGap;
+                Double xCor1 = minX + i * xGap ;
+                Double xCor2 = minX + i * xGap + 1 * xGap;
                 Double yCor = minY + maxYIndex * yGap + 0.5 * yGap;
 
-                Point point = new Point();
-                point.setColX(xCor);
-                point.setColY(yCor);
-                printPointList.add(point);
+                Point point1 = new Point();
+                Point point2 = new Point();
+                point1.setColX(xCor1);
+                point1.setColY(yCor);
+
+                point2.setColX(xCor2);
+                point2.setColY(yCor);
+                printPointList.add(point1);
+                printPointList.add(point2);
 //                System.out.println(xCor + " " + yCor);
 
 
@@ -106,13 +120,21 @@ public class WholeIndexOccupy {
             Integer maxYIndex = occupyPerX.getMaxYIndex();
             if (maxYIndex != -1 && minYIndex !=1000){
 
-                Double xCor = minX + i * xGap + 0.5 * xGap;
+//                Double xCor = minX + i * xGap + 0.5 * xGap;
+                Double xCor1 = minX + i * xGap;
+                Double xCor2 = minX + i * xGap + 1 * xGap;
                 Double yCor = minY + minYIndex * yGap + 0.5 * yGap;
 
-                Point point = new Point();
-                point.setColX(xCor);
-                point.setColY(yCor);
-                printPointList.add(point);
+//                Point point = new Point();
+                Point point1 = new Point();
+                Point point2 = new Point();
+                point1.setColX(xCor1);
+                point1.setColY(yCor);
+
+                point2.setColX(xCor2);
+                point2.setColY(yCor);
+                printPointList.add(point2);
+                printPointList.add(point1);
 
 //                System.out.println(xCor + " " + yCor);
             }
@@ -121,6 +143,10 @@ public class WholeIndexOccupy {
 
         printPointList.add(printPointList.get(0));
 
+        System.out.println("____________________________+++++++++++==");
+
+        occupyPointsArrayList = printPointList;
+
 //        for (int i =0;i< printPointList.size();i++){
 
 //            Point point = printPointList.get(i);
@@ -134,6 +160,7 @@ public class WholeIndexOccupy {
 //        System.out.println("print REAL end-----------");
 
         OperateFile operateFile = new OperateFile();
+        System.out.println(printPointList.size() + " ++++++++++++++++++++++++");
         operateFile.printPoint("Y:\\occupy.txt",printPointList);