【发布时间】: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