From 990782ab2c75805ef0390e40255ca817a02aa0bd Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期一, 16 十月 2023 10:35:49 +0800
Subject: [PATCH] 提交
---
ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java | 93 ++++++++++++++++++++--------------------------
1 files changed, 41 insertions(+), 52 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java b/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
index 24f018f..9f633bd 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
@@ -1,7 +1,11 @@
package com.ruoyi.utils.tube;
import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
+import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
+import org.gavaghan.geodesy.Ellipsoid;
+import org.gavaghan.geodesy.GeodeticCalculator;
+import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Comparator;
@@ -20,22 +24,22 @@
public class TubeTools {
public static void main(String[] args) {
// 鍋囪缁欏畾鐨勪笁涓潗鏍囩偣 A銆丅銆丆
- double x1 = 124.939903268;
- double y1 = 46.684520056;
- double x2 = 124.94049634327537;
- double y2 = 46.68442539350505;
- double x3 = 124.940552075;
- double y3 = 46.684416498;
+ GeoPoint pointA = new GeoPoint(124.939903268, 46.684520056, 143.3 - 0.73);
+ GeoPoint pointB = new GeoPoint(124.94034787826001, 46.68444909044429, 144.12232823014708);
+ GeoPoint pointC = new GeoPoint(124.940552075, 46.684416498, 144.5 - 0.81);
- double distance = getDistance(x1, y1, x3, y3);
- log.debug("鎬昏窛绂�:" + distance);
- double distance1 = getDistance(x1, y1, x2, y2);
- log.debug("璺濈璧风偣璺濈:" + distance1);
- double distance2 = getDistance(x2, y2, x3, y3);
- log.debug("璺濈缁堢偣璺濈:" + distance2);
+ double distance = getDistance(pointA, pointC);
+ double diffAC = pointA.getAltitude() - pointC.getAltitude();
+ log.info("AC鎬昏窛绂�:" + distance + " AC楂樺害宸細" + diffAC);
+ double distance1 = getDistance(pointA, pointB);
+ double diffAB = pointA.getAltitude() - pointB.getAltitude();
+ log.info("AB璺濈:" + distance1 + " AB楂樺害宸細" + diffAB);
+ double distance2 = getDistance(pointB, pointC);
+ double diffBC = pointB.getAltitude() - pointC.getAltitude();
+ log.info("BC璺濈:" + distance2 + " BC楂樺害宸細" + diffBC);
// 璁$畻鏂滅巼
- double slope1 = (y2 - y1) / (x2 - x1);
- double slope2 = (y3 - y2) / (x3 - x2);
+ double slope1 = (pointB.getLatitude() - pointA.getLatitude()) / (pointB.getLongitude() - pointA.getLongitude());
+ double slope2 = (pointC.getLatitude() - pointB.getLatitude()) / (pointC.getLongitude() - pointB.getLongitude());
// 璁剧疆鏂滅巼宸�肩殑闃堝��
double threshold = 0.000001;
@@ -49,29 +53,30 @@
}
/**
- * @鎻忚堪 璁$畻鍧愭爣
- * @鍙傛暟 [ardTubesDetails, alarmPointDistance]
- * @杩斿洖鍊� void
- * @鍒涘缓浜� 鍒樿嫃涔�
- * @鍒涘缓鏃堕棿 2023/6/8 14:38
- * @淇敼浜哄拰鍏跺畠淇℃伅
+ * 璁$畻鍧愭爣
+ *
+ * 鍒樿嫃涔�
+ * 2023/6/8 14:38
*/
public static GeoPoint CalculateCoordinates(List<ArdTubesDetails> ardTubesDetails, Integer alarmPointDistance) {
-
try {
+ if(StringUtils.isNull(alarmPointDistance))
+ {
+ log.debug("鎶ヨ鐐硅窛绂讳负绌猴紝鏃犳硶璁$畻鍧愭爣");
+ return null;
+ }
Comparator<ArdTubesDetails> comparator = Comparator.comparingInt(person -> Integer.parseInt(person.getInflectionPointNumber())); // 浣跨敤Collections.sort鏂规硶杩涜鎺掑簭
Collections.sort(ardTubesDetails, comparator);
- double x = ardTubesDetails.get(0).getLongitude();
- double y = ardTubesDetails.get(0).getLatitude();
+ GeoPoint point0 = new GeoPoint(ardTubesDetails.get(0).getLongitude(), ardTubesDetails.get(0).getLatitude(), ardTubesDetails.get(0).getAltitude() - ardTubesDetails.get(0).getDepth());
TreeMap<Integer, Double> distanceMap = new TreeMap<>();
TreeMap<Integer, Object> tubeMap = new TreeMap<>();
double distance = 0.0;
for (ArdTubesDetails atd : ardTubesDetails) {
- distance += getDistance(x, y, atd.getLongitude(), atd.getLatitude());
+ GeoPoint point = new GeoPoint(atd.getLongitude(), atd.getLatitude(), atd.getAltitude() - atd.getDepth());
+ distance += getDistance(point, point0);
distanceMap.put(Integer.parseInt(atd.getInflectionPointNumber()), distance);
tubeMap.put(Integer.parseInt(atd.getInflectionPointNumber()), atd);
- x = atd.getLongitude();
- y = atd.getLatitude();
+ point0 = point;
}
Integer num = 0;
double tempDistance = 0.0;
@@ -184,35 +189,19 @@
return angle;
}
- private static final double EARTH_RADIUS = 6378.137; // 6378.137涓哄湴鐞冨崐寰�(鍗曚綅:鍗冪背)
-
/**
* 鏍规嵁缁忕含搴︼紝璁$畻涓ょ偣闂寸殑璺濈
*
- * @param longitude1 绗竴涓偣鐨勭粡搴�
- * @param latitude1 绗竴涓偣鐨勭含搴�
- * @param longitude2 绗簩涓偣鐨勭粡搴�
- * @param latitude2 绗簩涓偣鐨勭含搴�
- * @return 杩斿洖璺濈 鍗曚綅鍗冪背
+ * @param GeoPoint pa 绗竴涓偣
+ * @param GeoPoint pb 绗簩涓偣
+ * @return 杩斿洖璺濈 鍗曚綅绫�
*/
- private static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
- // 绾害
- double lat1 = Math.toRadians(latitude1);
- double lat2 = Math.toRadians(latitude2);
- // 缁忓害
- double lng1 = Math.toRadians(longitude1);
- double lng2 = Math.toRadians(longitude2);
- // 绾害涔嬪樊
- double a = lat1 - lat2;
- // 缁忓害涔嬪樊
- double b = lng1 - lng2;
- // 璁$畻涓ょ偣璺濈鐨勫叕寮�
- double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
- Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
- // 寮ч暱涔樺湴鐞冨崐寰�, 杩斿洖鍗曚綅: 鍗冪背
- s = s * EARTH_RADIUS;
- //System.out.println("璺濈"+s);
- return s * 1000;
+ public static GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
+ public static double getDistance(GeoPoint pa, GeoPoint pb) {
+ GlobalCoordinates source = new GlobalCoordinates(pa.getLatitude(), pa.getLongitude());
+ GlobalCoordinates target = new GlobalCoordinates(pb.getLatitude(), pb.getLongitude());
+ double distance = geodeticCalculator.calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
+ double res = Math.sqrt(Math.pow(pa.getAltitude() - pb.getAltitude(), 2) + Math.pow(distance, 2));
+ return res;
}
-
}
--
Gitblit v1.9.3