| | |
| | | |
| | | import com.flightfeather.uav.common.utils.MapUtil |
| | | import com.flightfeather.uav.domain.entity.* |
| | | import com.flightfeather.uav.model.underwaygrid.GridCellAndData |
| | | import com.flightfeather.uav.model.underwaygrid.GridCellSop |
| | | import com.flightfeather.uav.model.underwaygrid.UnderwayGridModel |
| | | import com.flightfeather.uav.socket.eunm.FactorType |
| | | import org.springframework.beans.BeanUtils |
| | | import kotlin.math.PI |
| | | import kotlin.math.sqrt |
| | | |
| | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | // 统计每个网格中的均值 |
| | |
| | | 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 |
| | | rank |
| | | } |
| | | gridDataDetailList.add(dataDetail) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 计算坐标点在哪个卫星网格内 |
| | | * @date 2025.2.14 |
| | | * @param point 坐标点 |
| | | * @param gridCellList 卫星网格 |
| | | * 计算热力图网格,即网格周边扩散影响权重计算 |
| | | * @param gridDataDetail 网格监测数据 |
| | | * @param gridCellList 区域网格数组 |
| | | * @param option 区域网格参数信息 |
| | | * @param searchLength 计算周边八方向(上下左右及四个对角)网格的长度 |
| | | * @return 周边网格及对应的监测数据结果 |
| | | */ |
| | | 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 |
| | | fun heatMap( |
| | | gridDataDetail: GridDataDetail, gridCellList: List<GridCell?>, |
| | | option: GridGroupOption, searchLength: Int, |
| | | ): List<GridDataDetail> { |
| | | // 找到网格数据对应的网格信息 |
| | | val gridCell = gridCellList.find { it?.cellIndex == gridDataDetail.cellId } |
| | | ?: throw IllegalArgumentException("网格数据和给定的区域网格不匹配") |
| | | |
| | | // 获取周边网格 |
| | | val surroundGridCellList = |
| | | SatelliteGridUtil.searchDiffuseGrid(gridDataDetail.cellId, gridCellList, option, searchLength) |
| | | |
| | | // 使用走航网格权重模型,计算周边网格的监测数据值 |
| | | val underwayGridModel = UnderwayGridModel() |
| | | val dataList = listOf(GridCellAndData(gridCell, gridDataDetail)) |
| | | val gridCellSopList = surroundGridCellList.map { |
| | | GridCellSop( |
| | | it, |
| | | it.id.toString(), |
| | | it.cellIndex.toString(), |
| | | it.cellIndex.toString() |
| | | ) } |
| | | underwayGridModel.execute(dataList, gridCellSopList) |
| | | val resMap = underwayGridModel.outputResult() |
| | | |
| | | // 格式化结果并返回 |
| | | val result = mutableListOf<GridDataDetail>() |
| | | gridCellSopList.forEach { |
| | | val resGridDataDetail = GridDataDetail().apply { |
| | | dataId = gridDataDetail.dataId |
| | | groupId = gridDataDetail.groupId |
| | | cellId = it.gridCell.cellIndex |
| | | } |
| | | |
| | | val key = "${it.sourceName};${it.index}" |
| | | val d = resMap[key] |
| | | d?.forEach { (t, u) -> |
| | | val avg = u["综合(${t})"]?.average ?: .0 |
| | | resGridDataDetail.setFactorValue(FactorType.getByName(t), avg.toFloat()) |
| | | } |
| | | result.add(resGridDataDetail) |
| | | } |
| | | |
| | | return null |
| | | return result |
| | | } |
| | | |
| | | } |