feiyu02
2025-03-21 e5bdf2e02090357cbd580d54e6cd2406dd541760
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.flightfeather.uav.biz.satellite
 
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.GridCell
import kotlin.math.ceil
 
/**
 * 卫星网格计算工具
 */
object SatelliteGridUtil {
 
    /**
     * 计算坐标点在哪个卫星网格内
     * @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
    }
 
    /**
     * 计算扩散网格,根据给定网格,计算在其周围固定半径下的所有网格
     * 网格的形式为原始卫星遥测网格以及细分网格
     * 原始卫星遥测网格的编号顺序为从左到右,从上到下编号依次递增
     * 细分网格在原始卫星遥测网格的基础上,每个网格内部按从左到右,从上到下编号依次递增
     * @param gridCellIndex 中心点网格索引值
     * @param gridCellList 所有网格数组
     * @param option 网格组的参数信息
     * @param searchLength 扩散的网格半径数量
     * @return 计算得出的扩散网格对象数组
     */
    fun searchDiffuseGrid(
        gridCellIndex: Int,
        gridCellList: List<GridCell?>,
        option: GridGroupOption,
        searchLength: Int,
    ): List<GridCell> {
        return emptyList()
    }
 
    /**
     * 根据网格索引,获取其所在东西方向的网格索引范围
     * @param cellIndex 网格索引
     * @param width 网格宽度,指东西方向上的网格数量
     * @param height 网格高度,指南北方向上的网格数量
     * @return 返回网格索引值范围
     */
    fun getCellWidthRange(cellIndex: Int, width: Int, height: Int): Pair<Double, Double>? {
        val total = width * height;
        val x = ceil(cellIndex.toDouble() / total) - 1;
        val first = 1 + x * total
        val last = width + x * total;
        var scale = 0;
        while (scale < height) {
            val min = first + scale * width;
            val max = last + scale * width;
            if (cellIndex >= min && cellIndex <= max) {
                return min to max
            }
            scale++;
        }
        return null
    }
}