燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-08 436e03fe73a19bd485e23f78da5d851bbfe85d25
src/main/java/com/yssh/utils/CalculateUtils.java
@@ -1,8 +1,10 @@
package com.yssh.utils;
import java.text.SimpleDateFormat;
import java.awt.geom.Point2D;
import java.util.*;
import com.yssh.entity.Coordinate;
import com.yssh.entity.DistanceSuYuan;
import com.yssh.entity.MonitorPointPosition;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.referencing.CRS;
@@ -11,15 +13,6 @@
import org.opengis.referencing.crs.CoordinateReferenceSystem;
public class CalculateUtils {
   private final static SimpleDateFormat ymdh = new SimpleDateFormat("yyyyMMddHH");
   /**
    * 获取年月日时
    */
   public static String getYearMonthDayHour(Date date) {
      return ymdh.format(date);
   }
   /**
    * 默认地球半径,赤道半径(单位m)
    */
@@ -28,8 +21,7 @@
   /**
    * 转化为弧度(rad)
    */
   private static double rad(double d)
   {
   private static double rad(double d) {
      return d * Math.PI / 180.0;
   }
@@ -45,7 +37,7 @@
      s = s * EARTH_RADIUS1;
      return Math.round(s * 100) / 100;
      return round2(s);
   }
   /**
@@ -64,7 +56,21 @@
      // 计算距离,单位:米
      double distance = geodeticCalculator.getOrthodromicDistance();
      return Math.round(distance * 100) / 100;
      return round2(distance);
   }
   /**
    * 保留2位小数
    */
   public static double round2(double d) {
      return ((long) (d * 100)) / 100D;
   }
   /**
    * 保留6位小数
    */
   public static double round6(double d) {
      return ((long) (d * 1000000)) / 1000000D;
   }
   /**
@@ -82,14 +88,52 @@
         double angle = gc.getAzimuth();
         return Math.round(angle * 100) / 100;
         return round2(angle);
      } catch (Exception ex) {
         return 0;
      }
   }
   /**
    * 计算角度2
    */
   public static double getAngle2(double x1, double y1, double x2, double y2) {
      try {
         DirectPosition2D p1 = new DirectPosition2D(x1, y1);
         DirectPosition2D p2 = new DirectPosition2D(x2, y2);
         GeodeticCalculator gc = new GeodeticCalculator();
         gc.setStartingGeographicPoint(p1);
         gc.setDestinationGeographicPoint(p2);
         double angle = gc.getAzimuth();
         return round2(angle);
      } catch (Exception ex) {
         return 0;
      }
   }
   /**
    * 获取坐标
    *
    * @param su
    * @return
    */
   public static Coordinate getCoordinate(DistanceSuYuan su) {
      String[] sirs = su.getId().split("_");
      int x = Integer.parseInt(sirs[0]);
      int y = Integer.parseInt(sirs[1]);
      double lon = CalculateUtils.getLon(x, y);
      double lat = CalculateUtils.getLat(x, y);
      return new Coordinate(lon, lat);
   }
   /**
    * 计算经度
    *
    * @param @param  x
    * @param @param  y
    * @param @return 参数
@@ -103,11 +147,13 @@
      if (lon < 115 || lon > 116) {
         System.out.println("lon is invalid");
      }
      return lon;
      return round6(lon);
   }
   /**
    * 计算维度
    *
    * @param @param  x
    * @param @param  y
    * @param @return 参数
@@ -121,7 +167,8 @@
      if (lat < 39 || lat > 40) {
         System.out.println("lat is invalid");
      }
      return lat;
      return round6(lat);
   }
   /**
@@ -163,6 +210,16 @@
      return ids;
   }
   /**
    * 根据范围获取查询条件
    */
   public static String getFilterByExtend(MonitorPointPosition point, int range) {
      Integer x = point.getX();
      Integer y = point.getY();
      return String.format("x between %d and %d and y between %d and %d", x - range / 2, x + range / 2, y - range / 2, y + range / 2);
   }
   public static List<String> temporary(MonitorPointPosition point, int range) {
      List<String> ids3d = new ArrayList<>();
      Integer x = point.getX();
@@ -179,6 +236,72 @@
   }
   /**
    * 获取方向
    */
   public static String getDir(double direction) {
      if (direction < 0) {
         direction = direction + 360;
      }
      if (direction > 360) {
         direction = direction - 360;
      }
      if (direction >= 22.5 && direction < 67.5)
         return "东北";
      if (direction >= 67.5 && direction < 112.5)
         return "东";
      if (direction >= 112.5 && direction < 157.5)
         return "东南";
      if (direction >= 157.5 && direction < 202.5)
         return "南";
      if (direction >= 202.5 && direction < 247.5)
         return "西南";
      if (direction >= 247.5 && direction < 292.5)
         return "西";
      if (direction >= 292.5 && direction < 337.5)
         return "西北";
      return "北";
   }
   /**
    * 计算X、Y值的矩形框
    */
   public static List<Coordinate> calcRect(double x, double y) {
      double buffer = 10;
      double dis = round6(Math.sqrt(Math.pow(buffer / 2, 2) * 2));
      List<Coordinate> list = new ArrayList<>();
      list.add(getPointByDisAndAngle(x, y, 315, dis));
      list.add(getPointByDisAndAngle(x, y, 45, dis));
      list.add(getPointByDisAndAngle(x, y, 135, dis));
      list.add(getPointByDisAndAngle(x, y, 225, dis));
      return list;
   }
   /**
    * 根据距离和角度获取目标点
    */
   private static Coordinate getPointByDisAndAngle(double x, double y, double angle, double dis) {
      try {
         DirectPosition2D p1 = new DirectPosition2D(x, y);
         GeodeticCalculator gc = new GeodeticCalculator();
         gc.setStartingGeographicPoint(p1);
         gc.setDirection(angle, dis);
         Point2D dest = gc.getDestinationGeographicPoint();
         double newX = round6(dest.getX());
         double newY = round6(dest.getY());
         return new Coordinate(newX, newY);
      } catch (Exception ex) {
         return new Coordinate();
      }
   }
   /**
    * @param @return 参数
    * @return Double 返回类型
    * @throws
@@ -186,7 +309,7 @@
    * @Description: 计算风速
    */
   public static Double getWindSpeed(double v, double u) {
      return Math.sqrt(v * v + u * u);
      return round6(Math.sqrt(v * v + u * u));
   }
   /**
@@ -205,7 +328,8 @@
      } else if (u < 0 && v > 0) {
         result += 360;
      }
      return result;
      return round6(result);
   }
   /**