feiyu02
2025-03-21 e5bdf2e02090357cbd580d54e6cd2406dd541760
src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -2,6 +2,7 @@
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.*
import org.springframework.beans.BeanUtils
import kotlin.math.PI
import kotlin.math.sqrt
@@ -237,12 +238,13 @@
        realTimeDataList.forEach {
            if (it.longitude == null || it.latitude == null) return@forEach
            searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList)?.let { cell ->
                if (!dataMap.containsKey(cell)) {
                    dataMap[cell] = mutableListOf()
            SatelliteGridUtil.searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList)
                ?.let { cell ->
                    if (!dataMap.containsKey(cell)) {
                        dataMap[cell] = mutableListOf()
                    }
                    dataMap[cell]?.add(it)
                }
                dataMap[cell]?.add(it)
            }
        }
        // 统计每个网格中的均值
@@ -250,11 +252,26 @@
        val gridDataDetailList = mutableListOf<GridDataDetail>()
        dataMap.forEach { (k, v) ->
            val avgData = v.avg()
            val dataDetail = GridDataDetail().apply {
            val dataDetail = GridDataDetail()
            BeanUtils.copyProperties(avgData, dataDetail)
            dataDetail.apply {
                dataId = gridData?.id
                groupId = k.groupId
                cellId = k.cellIndex
                pm25 = avgData.pm25
//                no2 = avgData.no2
//                co = avgData.co
//                h2s = avgData.h2s
//                so2 = avgData.so2
//                o3 = avgData.o3
//                pm25 = avgData.pm25
//                pm10 = avgData.pm10
//                temperature = avgData.temperature
//                humidity = avgData.humidity
//                voc = avgData.voc
//                noi = avgData.noi
//                no = avgData.no
//                windSpeed
//                windDirection
                rank
            }
            gridDataDetailList.add(dataDetail)
@@ -269,27 +286,6 @@
        return gridDataDetailList
    }
    /**
     * 计算坐标点在哪个卫星网格内
     * @date 2025.2.14
     * @param point 坐标点
     * @param gridCellList 卫星网格
     */
    fun searchGirdIn(point: Pair<Double, Double>, gridCellList: List<GridCell?>): GridCell? {
        for (i in gridCellList.indices) {
            val gridCell = gridCellList[i] ?: continue
            val polygon = listOf(
                gridCell.point1Lon.toDouble() to gridCell.point1Lat.toDouble(),
                gridCell.point2Lon.toDouble() to gridCell.point2Lat.toDouble(),
                gridCell.point3Lon.toDouble() to gridCell.point3Lat.toDouble(),
                gridCell.point4Lon.toDouble() to gridCell.point4Lat.toDouble(),
            )
            if (MapUtil.isPointInPolygon(point, polygon)) {
                return gridCell
            }
        }
        return null
    }
}