如何检查坐标网格中是否存在坐标对(纬度,经度)? [英] How to check if a coordinate pair (lat,lon) exists in a coordinate grid?
问题描述
我有一种算法,可以在满足某些条件时使用地理坐标来计算形状.该算法将输出纬度列表和经度列表,如下所示.因此lat [0]和lon [0]将代表一个坐标对.我想创建一个纬度和经度图形状的布尔数组,如果算法输出中存在相应的坐标点,则索引将为真.我有netcdf文件中的原始纬度和经度信息,但是如何制作一个可以与算法输出进行比较的2d坐标点数组,然后使用匹配索引来创建此布尔数组?
I have an algorithm that computes shapes using geographic coordinates when certain conditions are satisfied. The algorithm outputs a latitude list and a longitude list like seen below. So lat[0] and lon[0] would represent a coordinate pair. I want to create a boolean array in the shape of a latitude and longitude map where the indices would be true if a corresponding coordinate point exists in the algorithm output. I have the original latitude and longitude information from the netcdf file, but how do I make a 2d array of coordinate points that can be compared against the algorithm output, and then use the matching indices to make this boolean array?
我尝试将纬度和经度合并为一个数组. len(lat)= 81,len(lon)= 480
,我需要一个(81,480)
数组.我认为我必须使用numpy where函数来确定坐标对匹配的位置.
I've tried combining the latitude and longitude into a single array. len(lat) = 81, len(lon) = 480
and I need an array of (81,480)
. I figure I would have to use an numpy where function to determine where the coordinate pairs match.
lat_alg = [-47.25 -47.25 -47.25 -48. -48. -48. -48. -48. -48. -48.
-48. -48.75 -48.75 -48.75 -48.75 -48.75 -48.75 -49.5 -49.5 -49.5
-49.5 -50.25 -50.25 -50.25]
lon_alg = [225.75 226.5 227.25 226.5 227.25 228. 228.75 229.5 230.25 231.
231.75 228. 228.75 229.5 230.25 231. 231.75 229.5 230.25 231.
231.75 230.25 231. 231.75]
我创建的布尔数组是... ar_tracker = np.zeros((len(lat),len(lon)))
The boolean array I create is ...
ar_tracker = np.zeros((len(lat),len(lon)))
我希望输出为1,坐标匹配.
and I want the output to be 1 where the coordinates match.
推荐答案
为了完全确定该对是否存在,建议您建立一个元组列表,其中每个元组都包含一对(纬度,经度).例如:
In order to be totally sure about if the pair exists, I suggest you build a list of tuples where each tuple contains a pair (lat,lon). For example:
def Mesh(X,Y):
A=[]
for x,y in zip(X,Y):
A.append((x,y))
return A
Coord=Mesh(lat_alg,lon_alg)
然后,如果您知道网格分辨率,则可以按以下步骤轻松检查对:
Then, if you know your grid resolution, you can easily check a pair as follows:
coord=(-49.5,230.25)
if coord in Coord:
print('True')
else:
print('False')
这篇关于如何检查坐标网格中是否存在坐标对(纬度,经度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!