BuildYardFast.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import java.io.FileNotFoundException;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. public class BuildYardFast {
  6. public void buildYard(String rulerFileName,String yardFileName,Integer rulerBegin,Integer rulerEnd) throws FileNotFoundException {
  7. ArrayList<Point> yardPointsList = gpsExchange(yardFileName);
  8. ArrayList<Point> rulerPointsList = gpsExchange(rulerFileName);
  9. Point rulerPointBegin = rulerPointsList.get(0);
  10. Point rulerPointEnd = rulerPointsList.get(1);
  11. Point pointYardBegin = cal(rulerPointBegin,rulerPointEnd,rulerBegin);
  12. Point pointYardEnd = cal(rulerPointBegin,rulerPointEnd,rulerEnd);
  13. ArrayList<Point> result = new ArrayList<>();
  14. result.add(pointYardBegin);
  15. result.addAll(yardPointsList);
  16. result.add(pointYardEnd);
  17. OperateFile operateFile = new OperateFile();
  18. String fileOutPath = "/Users/haoqianpan/file/programfile/gpsexc/out/";
  19. operateFile.printPoint(fileOutPath + yardFileName,arrayListNeg(result));
  20. }
  21. public ArrayList<Point> gpsExchange(String fileName) throws FileNotFoundException {
  22. ArrayList<GpsCor> pointArrayList;
  23. ArrayList<Point> dataList = new ArrayList<>();
  24. OperateFile operateFile = new OperateFile();
  25. String fileInputPath = "/Users/haoqianpan/file/programfile/gpsexc/in/";
  26. pointArrayList = operateFile.readlatlonCor(fileInputPath + fileName);
  27. for (int i = 0 ; i < pointArrayList.size();i++){
  28. GpsCor gpsCor = pointArrayList.get(i);
  29. Double lat = gpsCor.getLat();
  30. Double lon = gpsCor.getLon();
  31. GpsConvertMethod gpsConvertMethod = new GpsConvertMethod("MCT2XY",lat,lon,55.5,11789993,3128152);
  32. double[] xyCor = gpsConvertMethod.coordinatexy;
  33. Double x = xyCor[0];
  34. Double y = xyCor[1];
  35. Point point = new Point();
  36. point.setColX(x);
  37. point.setColY(y);
  38. dataList.add(point);
  39. }
  40. return dataList;
  41. }
  42. // public Point cal(Double xStart,Double yStart,Double xEnd,Double yEnd,Double rulerIndex){
  43. public Point cal(Point pointBeginInput,Point pointEndInput,Integer rulerIndex){
  44. Double xStart = pointBeginInput.getColX();
  45. Double yStart = pointBeginInput.getColY();
  46. Double xEnd = pointEndInput.getColX();
  47. Double yEnd = pointEndInput.getColY();
  48. //////
  49. Point pointStart = new Point();
  50. pointStart.setColX(xStart);
  51. pointStart.setColY(yStart);
  52. Point pointEnd = new Point();
  53. pointEnd.setColX(xEnd);
  54. pointEnd.setColY(yEnd);
  55. /////
  56. CurveTool curveTool = new CurveTool();
  57. ArrayList<Double> lineParamList = curveTool.calLineabc(pointStart,pointEnd);
  58. Double k = lineParamList.get(0);
  59. Double counterValue = Math.sqrt(Math.pow(rulerIndex,2)/(Math.pow(k,2) + 1));
  60. Point point = new Point();
  61. if (xStart >= xEnd){
  62. double xTemp = xStart - counterValue;
  63. double yTemp = curveTool.getLineYValue(xTemp,lineParamList);
  64. point.setColX(xTemp);
  65. point.setColY(yTemp);
  66. }
  67. if (xStart < xEnd){
  68. double xTemp = xStart + counterValue;
  69. double yTemp = curveTool.getLineYValue(xTemp,lineParamList);
  70. point.setColX(xTemp);
  71. point.setColY(yTemp);
  72. }
  73. System.out.println(pointDistance(point,pointStart));
  74. return point;
  75. }
  76. public ArrayList<Point> arrayListNeg(ArrayList<Point> arrayList){
  77. for (int i = 0 ; i < arrayList.size();i++){
  78. Point pointOld = arrayList.get(i);
  79. Point pointNew = new Point();
  80. pointNew.setColX(pointOld.getColX());
  81. pointNew.setColY( 0 - pointOld.getColY());
  82. arrayList.set(i,pointNew);
  83. }
  84. return arrayList;
  85. }
  86. public double pointDistance(Point point1 ,Point point2){
  87. Double x1 = point1.getColX();
  88. Double y1 = point1.getColY();
  89. Double x2 = point2.getColX();
  90. Double y2 = point2.getColY();
  91. return Math.sqrt(Math.pow(x1 - x2,2) + Math.pow(y1 - y2,2));
  92. }
  93. }