feiyu02
2025-02-07 e133600480d5f688a8375db7708fe531b4726f4a
src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -1,7 +1,10 @@
package com.flightfeather.uav.biz.satellite
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.GridCell
import com.flightfeather.uav.domain.entity.GridData
import com.flightfeather.uav.domain.entity.GridDataDetail
import kotlin.math.PI
import kotlin.math.sqrt
@@ -87,15 +90,15 @@
        val p2 = p.point2Lon to p.point2Lat
        val p3 = p.point3Lon to p.point3Lat
        val p4 = p.point4Lon to p.point4Lat
        // p1、p3的经纬度单位差值
        val dx1 = (p3.first - p1.first) / scale.toBigDecimal()
        val dy1 = (p3.second - p1.second) / scale.toBigDecimal()
        // p1、p4的经纬度单位差值
        val dx1 = (p4.first - p1.first) / scale.toBigDecimal()
        val dy1 = (p4.second - p1.second) / scale.toBigDecimal()
        // p1、p2的经纬度单位差值
        val dx2 = (p2.first - p1.first) / scale.toBigDecimal()
        val dy2 = (p2.second - p1.second) / scale.toBigDecimal()
        // p3、p4的经纬度单位差值
        val dx3 = (p4.first - p3.first) / scale.toBigDecimal()
        val dy3 = (p4.second - p3.second) / scale.toBigDecimal()
        // p4、p3的经纬度单位差值
        val dx3 = (p3.first - p4.first) / scale.toBigDecimal()
        val dy3 = (p3.second - p4.second) / scale.toBigDecimal()
        // 中心点和p1的经纬度单位差值
        val dxC = (p.longitude - p1.first) / scale.toBigDecimal()
        val dyC = (p.latitude - p1.second) / scale.toBigDecimal()
@@ -116,14 +119,14 @@
                newGridCell1.point1Lon = g.point1Lon + dx1 * row.toBigDecimal()
                newGridCell1.point1Lat = g.point1Lat + dy1 * row.toBigDecimal()
                // 左下角顶点根据所在行数在原始网格顶点基础上增加偏移量(比左上角顶点多一个偏移)
                newGridCell1.point3Lon = g.point1Lon + dx1 * (row + 1).toBigDecimal()
                newGridCell1.point3Lat = g.point1Lat + dy1 * (row + 1).toBigDecimal()
                newGridCell1.point4Lon = g.point1Lon + dx1 * (row + 1).toBigDecimal()
                newGridCell1.point4Lat = g.point1Lat + 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.point3Lon = newGridCell1.point4Lon + dx3
                newGridCell1.point3Lat = newGridCell1.point4Lat + dy3
                // 中心点在细分网格左上角的基础上增加固定偏移量
                newGridCell1.longitude = newGridCell1.point1Lon + dxC
                newGridCell1.latitude = newGridCell1.point1Lat + dyC
@@ -160,4 +163,66 @@
        return newGridCellList
    }
    /**
     * 拆分数据,将原始卫星网格遥测数据映射到对应细分网格上
     * @param subGridCellList 细分网格, 按照
     * @param subGridData 细分网格对应的数据索引
     * @param originGridDataDetailList 细分网格所属网格的原始网格数据
     */
    fun splitData(
        subGridCellList: List<GridCell?>, subGridData: GridData, originGridDataDetailList: List<GridDataDetail?>
    ): List<GridDataDetail> {
        if (subGridCellList.isEmpty() || originGridDataDetailList.isEmpty()) return emptyList()
        val result = mutableListOf<GridDataDetail>()
        // 将细分网格按照父网格id和自身网格id进行升序排列
        val _subGridCellList = subGridCellList.sortedWith(Comparator { o1, o2 ->
            if (o1 == null && o2 == null) {
                return@Comparator 0
            } else if (o1 == null) {
                return@Comparator -1
            } else if (o2 == null) {
                return@Comparator 1
            } else {
                if (o1.fatherCellIndex == o2.fatherCellIndex) {
                    return@Comparator o1.cellIndex - o2.cellIndex
                } else {
                    return@Comparator o1.fatherCellIndex - o2.fatherCellIndex
                }
            }
        })
        // 将原始网格数据按照网格id升序排列
        val _originGridDataDetailIterator = originGridDataDetailList.sortedBy { it?.cellId }.iterator()
        var fatherGridData = _originGridDataDetailIterator.next()
        // 遍历细分网格,为每个细分网格生成一条网格数据
        _subGridCellList.forEach {
            while (fatherGridData?.cellId != it?.fatherCellIndex && _originGridDataDetailIterator.hasNext()) {
                fatherGridData = _originGridDataDetailIterator.next()
            }
            val subGridDataDetail = GridDataDetail().apply {
                dataId = subGridData.id
                groupId = it?.groupId
                cellId = it?.cellIndex
                pm25 = fatherGridData?.pm25
                rank = fatherGridData?.rank
            }
            result.add(subGridDataDetail)
        }
        return result
    }
    /**
     * 数据融合
     * @param realTimeDataList 待融合的走航监测数据
     * @param gridData 融合后的数据组索引
     * @param gridCellList 待融合的卫星网格
     */
    fun dataFusion(realTimeDataList:List<BaseRealTimeData>, gridData: GridData, gridCellList: List<GridCell?>) {
    }
}