From 2e024c986c14943a41f7bfe913cfef0cede64198 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 29 七月 2025 17:37:54 +0800 Subject: [PATCH] 2025.7.29 1. 动态溯源模块添加记录删除等debug功能 --- src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt | 144 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 141 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt index bcfe4e2..e9092d6 100644 --- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt +++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt @@ -1,18 +1,156 @@ package com.flightfeather.uav.biz.sourcetrace.model +import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig +import com.flightfeather.uav.common.net.AMapService +import com.flightfeather.uav.common.utils.MapUtil +import com.flightfeather.uav.domain.entity.BaseRealTimeData +import com.flightfeather.uav.domain.entity.avg +import kotlin.math.PI + /** * 鍔ㄦ�佹函婧愭薄鏌撳尯鍩� * 閫氳繃鍦板浘鍧愭爣鐐瑰舰鎴愬杈瑰舰鏉ユ弿杩颁竴鍧楁薄鏌撳尯鍩� * @date 2025/5/27 * @author feiyu02 */ -class PollutedArea { +class PollutedArea() { - var name: String? = null + /** + * 婧簮瑙掑害鍙缃� + */ - // 姹℃煋鑼冨洿鍖哄煙(缁忕含搴﹀杈瑰舰) + constructor( + historyData: List<BaseRealTimeData>, + exceptionData: List<BaseRealTimeData>, + config: RTExcWindLevelConfig, + windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?, + ) : this() { + distanceType = windLevelCondition?.distanceType + distanceRange = distanceType?.disRange + distanceDes = distanceType?.des + windLevelCondition?.let { sourceTrace(historyData, exceptionData, config, it) } + } + + var address: String? = null + + // 姹℃煋鑼冨洿鎵囧舰鍖哄煙(缁忕含搴﹀杈瑰舰) var polygon: List<Pair<Double, Double>>? = null + + // 杩戣窛绂绘薄鏌撳渾褰㈠尯鍩� + var closePolygon: List<Pair<Double, Double>>? = null // 姹℃煋鍙兘鐨勫彂鐢熻窛绂� var distanceType: DistanceType? = null + + var distanceRange: Pair<Double, Double>? = null + var distanceDes: String? = null + + /** + * 鍙嶅悜婧簮 + */ + private fun sourceTrace( + historyData: List<BaseRealTimeData>, + exceptionData: List<BaseRealTimeData>, + config: RTExcWindLevelConfig, + windLevelCondition: RTExcWindLevelConfig.WindLevelCondition, + ) { + val avgData = if (exceptionData.size == 1) { + exceptionData.first() + } else { + exceptionData.avg() + } + + val pair = avgData.longitude!!.toDouble() to avgData.latitude!!.toDouble() + + polygon = calSector( + avgData.windDirection!!.toDouble(), + pair, + windLevelCondition.distanceType.disRange, + config.sourceTraceDegOffset + ).map { + // 灏嗗潗鏍囪浆鎹负gcj02锛堢伀鏄熷潗鏍囩郴锛夛紝鍥犱负姹℃煋婧愬満鏅俊鎭兘涓烘鍧愭爣绯� + MapUtil.wgs84ToGcj02(it) + } + + closePolygon = closeSourceTrace(historyData, pair).map { + // 灏嗗潗鏍囪浆鎹负gcj02锛堢伀鏄熷潗鏍囩郴锛夛紝鍥犱负姹℃煋婧愬満鏅俊鎭兘涓烘鍧愭爣绯� + MapUtil.wgs84ToGcj02(it) + } + + if (config.isSearchAddress) { + try { + val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(pair)) + this.address = address.district + address.township + address.street +// Thread.sleep(100) + } catch (e: Exception) { + e.printStackTrace() + } + } + + } + + /** + * 鏍规嵁涓績鐐瑰潗鏍囥�侀鍚戝拰婧簮璺濈锛屼互鍙婄粰瀹氱殑澶硅锛岃绠椾互涓績鐐规寜鐓ч鍚戝悜澶栨墿鏁e舰鎴愮殑鎵囧舰鐨勭偣鍧愭爣 + * @param windDir 椋庡悜锛屽崟浣嶏細搴� + * @param center 涓績鐐瑰潗鏍囩粡绾害 + * @param distanceRange 婧簮璺濈鑼冨洿锛屽崟浣嶏細绫� + * @param defaultDegOffset 鎵╂暎鍋忕Щ瑙掑害 + * @return 澶氳竟褰㈤《鐐瑰潗鏍囬泦鍚� + */ + private fun calSector( + windDir: Double, + center: Pair<Double, Double>, + distanceRange: Pair<Double, Double>, + defaultDegOffset: Double = 60.0, + ): List<Pair<Double, Double>> { + + val sDeg = windDir - defaultDegOffset / 2 + val eDeg = windDir + defaultDegOffset / 2 + + val result = mutableListOf<Pair<Double, Double>>() + + if (distanceRange.first == .0) { +// result.add(center) + var startDeg = 0 + while (startDeg <= 360) { + val p = MapUtil.getPointByLen(center, distanceRange.second, startDeg * PI / 180) + result.add(p) + startDeg++ + } + } else { + // 浠庡紑濮嬭搴﹀惊鐜绠楀潗鏍囩偣鑷崇粨鏉熻搴︼紝姝ラ暱1掳 + var startDeg = sDeg + while (startDeg <= eDeg) { + val p = MapUtil.getPointByLen(center, distanceRange.first, startDeg * PI / 180) + result.add(p) + startDeg++ + } + if (distanceRange.second > .0) { + // 姝ゅ闇�瑕佷粠缁撴潫瑙掑害寮�濮嬪弽鍚戝惊鐜绠楄嚦寮�濮嬭搴︼紝姝ラ暱1掳锛屼娇寰椾袱缁勫潗鏍囩偣鎸夐『搴忔帓鍒楋紝鍙粯鍒跺搴旂殑澶氳竟褰� + startDeg = eDeg + while (startDeg >= sDeg) { + val p = MapUtil.getPointByLen(center, distanceRange.second, startDeg * PI / 180) + result.add(p) + startDeg-- + } + } + } + + return result + } + + private fun closeSourceTrace( + historyData: List<BaseRealTimeData>, + center: Pair<Double, Double>, + ): List<Pair<Double, Double>> { + val result = mutableListOf<Pair<Double, Double>>() + var startDeg = 0 + while (startDeg <= 360) { + val p = MapUtil.getPointByLen(center, DistanceType.TYPE1.disRange.second, startDeg * PI / 180) + result.add(p) + startDeg++ + } + + return result + } } \ No newline at end of file -- Gitblit v1.9.3