| | |
| | | |
| | | 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 |
| | | |
| | |
| | | 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 |
| | | // 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) |
| | |
| | | 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 |
| | | } |
| | | |
| | | } |