【问题标题】:'Lining up' large lat/lon grid with smaller lat/lon grid\'排队\'大纬度/经度网格和较小的纬度/经度网格
【发布时间】:2022-10-18 04:04:45
【问题描述】:

假设我有一大堆值,它们代表形状为 x 的地形纬度位置。我还有另一个表示地形经度值的值数组,形状为 y。 x 和 y 中的所有值都以 0.005 度等距分布。换句话说:

lons[0:10] = [-130.0, -129.995, -129.99, -129.985, -129.98, -129.975, -129.97, -129.965, -129.96, -129.955]
lats[0:10] = [55.0, 54.995, 54.99, 54.985, 54.98, 54.975, 54.97, 54.965, 54.96, 54.955]

我有第二个数据集,该数据集投影在不规则间隔的纬度/经度网格中(但等距间隔约 25 米),其尺寸为 [m,n] 大,位于 x 和 y 的域内。此外,我们还拥有第二个数据集中的所有纬度/经度点。我想对网格进行“排列”,以使 [m,n] 的每个值都与较大网格内的最近邻地形值相匹配。我可以使用以下代码执行此操作,其中我基本上循环遍历数据集 2 中的每个纬度/经度值,并尝试从数据集 1 中找到计算的纬度/经度值的 argmin:

for a in range(0,lats.shape[0]):
    # Loop through the ranges
    for r in range(0,lons.shape[0]):

        # Access the elements
        tmp_lon = lons[r]
        tmp_lat = lats[a]

        # Now we need to find where the tmp_lon and tmp_lat match best with the index from new_lats and new_lons
        idx = (np.abs(new_lats - tmp_lat)).argmin()
        idy = (np.abs(new_lons - tmp_lon)).argmin()

        # Make our final array!
        second_dataset_trn[a,r] = first_dataset_trn[idy,idx]

除了它异常缓慢。是否有另一种方法,通过包、库等可以加快速度?

【问题讨论】:

    标签: python gis projection


    【解决方案1】:

    您可以查看以下先前的问题,以迭代两个列表,这可能会提高您的速度:Is there a better way to iterate over two lists, getting one element from each list for each iteration?

    对示例代码的可能更正:假设您的数组以纬度、经度的标准 GIS 方式组织,我相信您的 idxidy 变量分配有错误 - 接收分配的变量应该交换(idx 应该是 idy,并且另一种方式)。例如:

            # Now we need to find where the tmp_lon and tmp_lat match best with the index from new_lats and new_lons
            idy = (np.abs(new_lats - tmp_lat)).argmin()
            idx = (np.abs(new_lons - tmp_lon)).argmin()
    

    【讨论】:

      猜你喜欢
      • 2019-07-04
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2012-02-16
      • 1970-01-01
      • 2013-09-09
      相关资源
      最近更新 更多