From 6d766eed50f34b102e607ea471f2ee565a8b9d30 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 17 一月 2025 16:15:43 +0800
Subject: [PATCH] 1. 修改融合数据逻辑中,融合数据id数组为先排序后转换为字符串,修复同一批原始数据因为id排序不一样被判定为不同的融合数据的问题;

---
 src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt |  127 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 104 insertions(+), 23 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
index 3d37e30..0322e9a 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -1,6 +1,8 @@
 package com.flightfeather.uav.biz.satellite
 
 import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.domain.entity.GridCell
+import kotlin.math.PI
 import kotlin.math.sqrt
 
 /**
@@ -10,30 +12,36 @@
  * @date 2025/1/8
  * @author feiyu02
  */
-class SatelliteGridManage {
+object SatelliteGridManage {
 
     /**
      * 鏍规嵁姝f柟褰㈢綉鏍间腑蹇冪偣鍧愭爣锛岃绠�4涓《鐐瑰潗鏍�
+     * 缃戞牸涓績鐐瑰潗鏍囨寜鐓т粠宸﹀埌鍙炽�佷粠涓婂埌涓嬬殑椤哄簭鎺掑垪
+     * @param points 缃戞牸涓績鍧愭爣鐐规暟缁�
      */
-    fun calGridVertex(points:List<Pair<Double, Double>>):List<Array<Pair<Double, Double>>> {
+    fun calGridVertex(points: List<Pair<Double, Double>>): List<GridVertex> {
+        // 缃戞牸灏戜簬2涓紝鍒欐棤娉曠粯鍒�
         if (points.size < 2) return emptyList()
-        val p1 = points[0];
-        val p2 = points[1];
+        // 鑾峰彇鍓嶄袱涓綉鏍�
+        // Fixme 2025.01.10: 鐩墠鍏堢畝鍖栭�昏緫锛屾寜鐓у墠涓や釜鐐规槸宸﹀彸鎺掑竷锛屼笖鐐筽2鍦ㄧ偣p1鐨勪笢杈�
+        val p1 = points[0]
+        val p2 = points[1]
         // 涓や腑蹇冪偣闂寸殑瑙掑害
-        val angle = MapUtil.getAngle(p1.first, p1.second, p2.first, p2.second);
+        val angle = MapUtil.getAngle(p1.first, p1.second, p2.first, p2.second)
         // 涓や腑蹇冪偣闂寸殑璺濈
-        val dis = MapUtil.getDistance(p1.first, p1.second, p2.first, p2.second);
+        val dis = MapUtil.getDistance(p1.first, p1.second, p2.first, p2.second)
         // 缃戞牸姝f柟褰㈠瑙掔嚎鐨勪竴鍗婇暱搴�
-        val halfDiagonal = sqrt((dis / 2) * (dis / 2) * 2);
+        val halfDiagonal = sqrt((dis / 2) * (dis / 2) * 2)
         // 璁$畻棣栦釜姝f柟褰㈠悇椤剁偣鐩稿浜庝腑蹇冪偣鐨勮搴︼紝寰楀埌姝f柟褰㈠悇椤剁偣鐨勫潗鏍�
-        val angle1 = MapUtil.plusAngle(angle, 45.0);
-        val gp1 = MapUtil.getPointByLen(p1, halfDiagonal, angle1);
-        val angle2 = MapUtil.plusAngle(angle1, 90.0);
-        val gp2 = MapUtil.getPointByLen(p1, halfDiagonal, angle2);
-        val angle3 = MapUtil.plusAngle(angle2, 90.0);
-        val gp3 = MapUtil.getPointByLen(p1, halfDiagonal, angle3);
-        val angle4 = MapUtil.plusAngle(angle3, 90.0);
-        val gp4 = MapUtil.getPointByLen(p1, halfDiagonal, angle4);
+        // 4涓《鐐规寜鐓т粠宸︿笂瑙掑紑濮嬶紝椤烘椂閽堟柟鍚戠殑椤哄簭杩涜鎺掑垪
+        val angle1 = MapUtil.plusAngle(angle, 45.0 + 180.0)
+        val gp1 = MapUtil.getPointByLen(p1, halfDiagonal, angle1 * PI / 180)
+        val angle2 = MapUtil.plusAngle(angle1, 90.0)
+        val gp2 = MapUtil.getPointByLen(p1, halfDiagonal, angle2 * PI / 180)
+        val angle3 = MapUtil.plusAngle(angle2, 90.0)
+        val gp3 = MapUtil.getPointByLen(p1, halfDiagonal, angle3 * PI / 180)
+        val angle4 = MapUtil.plusAngle(angle3, 90.0)
+        val gp4 = MapUtil.getPointByLen(p1, halfDiagonal, angle4 * PI / 180)
         // 璁$畻4涓《鐐瑰垎鍒笌涓績鐐圭殑缁忕含搴﹀樊鍊�
         val dx1 = gp1.first - p1.first
         val dy1 = gp1.second - p1.second
@@ -45,21 +53,94 @@
         val dy4 = gp4.second - p1.second
 
         // 寰楀埌鎵�鏈夋鏂瑰舰缃戞牸鐨�4涓《鐐逛俊鎭�
-        return points.map { p->
-            arrayOf(
-                p.first + dx1 to p.second + dy1,
-                p.first + dx2 to p.second + dy2,
-                p.first + dx3 to p.second + dy3,
-                p.first + dx4 to p.second + dy4,
+        return points.map { p ->
+            GridVertex(
+                p.first + dx1, p.second + dy1,
+                p.first + dx2, p.second + dy2,
+                p.first + dx3, p.second + dy3,
+                p.first + dx4, p.second + dy4,
             )
         }
     }
 
     /**
-     * 鎷嗗垎缃戞牸
+     * 鎷嗗垎缃戞牸涓虹粏鍒嗙綉鏍�
+     * 鏍规嵁鐩镐技鐭╁舰鐨勫師鐞嗭紝鍙互鍒嗗埆鎸夋瘮渚嬪緱鍒版瘡涓粏鍒嗙綉鏍肩殑缁忕含搴�
+     * @param gridCellList 鍘熷缃戞牸鏁扮粍
+     * @param scale 鎷嗗垎鐨勭郴鏁帮紝渚嬪 2锛岃〃绀哄皢鍘熸湁缃戞牸鎸夎竟闀跨殑 1/2 鎷嗗垎鎴� 2 * 2 鐨�4涓綉鏍�
      */
-    fun splitGrid() {
+    fun splitGrid(gridCellList: List<GridCell>, scale: Int): List<GridCell> {
+        if (scale <= 0) throw IllegalArgumentException("缃戞牸鎷嗗垎鐨勬暟閲忎笉鑳藉皬浜�1")
+        // 鎷嗗垎绯绘暟涓�1锛屽垯琛ㄧず涓嶆媶鍒�
+        if (scale == 1) return gridCellList
+        if (gridCellList.isEmpty()) return emptyList()
 
+        val newGridCellList = mutableListOf<GridCell>()
+
+        // 鏍规嵁鍑芥暟[calGridVertex]鐢熸垚鐨勭綉鏍�4涓《鐐瑰潗鏍囷紝浠ヤ笂鍖椾笅鍗楀乏瑗垮彸涓滄柟鍚戜负鏍囧噯
+        // 璁$畻棣栦釜缃戞牸涓績鍧愭爣鐐瑰垎鍒拰4涓《鐐圭殑缁忕含搴﹀樊鍊�
+        val p = gridCellList[0]
+        // 锛堥�氳繃杩戜技骞抽潰鍧愭爣绯荤殑鏂瑰紡锛夋牴鎹崟涓師濮嬬綉鏍肩殑4涓《鐐瑰潗鏍囷紝鍒嗗埆纭畾浠ヤ笅涓夌粍鍧愭爣鐐逛箣闂寸殑缁忕含搴﹀崟浣嶅亸绉婚噺
+        val p1 = p.point1Lon to p.point1Lat
+        val p2 = p.point2Lon to p.point2Lat
+        val p3 = p.point3Lon to p.point3Lat
+        val p4 = p.point4Lon to p.point4Lat
+        // p1銆乸3鐨勭粡绾害鍗曚綅宸��
+        val dx1 = (p3.first - p1.first) / scale.toBigDecimal()
+        val dy1 = (p3.second - p1.second) / scale.toBigDecimal()
+        // p1銆乸2鐨勭粡绾害鍗曚綅宸��
+        val dx2 = (p2.first - p1.first) / scale.toBigDecimal()
+        val dy2 = (p2.second - p1.second) / scale.toBigDecimal()
+        // p3銆乸4鐨勭粡绾害鍗曚綅宸��
+        val dx3 = (p4.first - p3.first) / scale.toBigDecimal()
+        val dy3 = (p4.second - p3.second) / scale.toBigDecimal()
+        // 涓績鐐瑰拰p1鐨勭粡绾害鍗曚綅宸��
+        val dxC = (p.longitude - p1.first) / scale.toBigDecimal()
+        val dyC = (p.latitude - p1.second) / scale.toBigDecimal()
+
+        // 缃戞牸琛屽惊鐜�
+        for (row in 0 until scale) {
+            val newGridCell1 = GridCell()
+
+            // 纭畾姣忎竴琛岄涓粏鍒嗙綉鏍肩殑涓績鍧愭爣鍜�4涓《鐐瑰潗鏍�
+            // 宸︿笂瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺
+            newGridCell1.point1Lon = p1.first + dx1 * row.toBigDecimal()
+            newGridCell1.point1Lat = p1.second + dy1 * row.toBigDecimal()
+            // 宸︿笅瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺锛堟瘮宸︿笂瑙掗《鐐瑰涓�涓亸绉伙級
+            newGridCell1.point3Lon = p1.first + dx1 * (row + 1).toBigDecimal()
+            newGridCell1.point3Lat = p1.second + dy1 * (row + 1).toBigDecimal()
+            // 鍙充笂瑙掗《鐐瑰湪缁嗗垎缃戞牸宸︿笂瑙掔殑鍩虹涓婂鍔犵浉搴旂殑鍋忕Щ閲�
+            newGridCell1.point2Lon = newGridCell1.point1Lon + dx2
+            newGridCell1.point2Lat = newGridCell1.point1Lat + dy2
+            // 鍙充笅瑙掗《鐐瑰湪缁嗗垎缃戞牸宸︿笅瑙掔殑鍩虹涓婂鍔犵浉搴旂殑鍋忕Щ閲�
+            newGridCell1.point4Lon = newGridCell1.point3Lon + dx3
+            newGridCell1.point4Lat = newGridCell1.point3Lat + dy3
+            // 涓績鐐瑰湪缁嗗垎缃戞牸宸︿笂瑙掔殑鍩虹涓婂鍔犲浐瀹氬亸绉婚噺
+            newGridCell1.longitude = newGridCell1.point1Lon + dxC
+            newGridCell1.latitude = newGridCell1.point1Lat + dyC
+
+            // 鍔犲叆缁撴灉闆嗗悎
+            newGridCellList.add(newGridCell1)
+
+            // 缃戞牸鍒楀惊鐜�(浠庣2鍒楀紑濮�)
+            for (col in 1 until scale) {
+                val newGridCell = GridCell()
+                newGridCell.point1Lon = newGridCell1.point1Lon + dx2 * col.toBigDecimal()
+                newGridCell.point1Lat = newGridCell1.point1Lat + dy2 * col.toBigDecimal()
+                newGridCell.point2Lon = newGridCell1.point2Lon + dx2 * col.toBigDecimal()
+                newGridCell.point2Lat = newGridCell1.point2Lat + dy2 * col.toBigDecimal()
+                newGridCell.point3Lon = newGridCell1.point3Lon + dx3 * col.toBigDecimal()
+                newGridCell.point3Lat = newGridCell1.point3Lat + dy3 * col.toBigDecimal()
+                newGridCell.point4Lon = newGridCell1.point4Lon + dx3 * col.toBigDecimal()
+                newGridCell.point4Lat = newGridCell1.point4Lat + dy3 * col.toBigDecimal()
+                newGridCell.longitude = newGridCell.point1Lon + dxC
+                newGridCell.latitude = newGridCell.point1Lat + dyC
+
+                newGridCellList.add(newGridCell)
+            }
+        }
+
+        return newGridCellList
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3