我有一个由两个边界数组组成的网格:lon_bnds
和lat_bnds
。目标是选取网格内的点。
下面是一个例子:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
lon_bnds = np.array([[-77.9645 , -77.56074 , -77.162025, -76.76827 , -76.37937 ],
[-77.88815 , -77.48613 , -77.08915 , -76.69711 , -76.30993 ],
[-77.811676, -77.41139 , -77.01614 , -76.62582 , -76.24034 ],
[-77.73638 , -77.337814, -76.944275, -76.55565 , -76.17186 ],
[-77.66197 , -77.265114, -76.87326 , -76.48632 , -76.1042 ]])
lat_bnds = np.array([[-77.34674 , -77.35804 , -77.36858 , -77.378395, -77.38752 ],
[-77.28847 , -77.299614, -77.31001 , -77.31969 , -77.328674],
[-77.23022 , -77.24122 , -77.25147 , -77.26101 , -77.26986 ],
[-77.17193 , -77.182785, -77.192894, -77.20229 , -77.211006],
[-77.11363 , -77.12434 , -77.13431 , -77.14357 , -77.15215 ]])
plt.scatter(lon_bnds, lat_bnds, label='corner')
d = {'longitude': [-79, -77.2, -77, -75.5], 'latitude': [-77.4, -77.2, -77.3, -77.3]}
df_points = pd.DataFrame(data=d)
plt.scatter(df_points['longitude'], df_points['latitude'], c='r', label='points')
plt.legend()
结果应该是具有两个内部点的DataFrame。
我也发现这个question很有用,但是他们使用kdTree来搜索周围的点,而不是像我的例子那样使用精确的边界数组。
1条答案
按热度按时间sgtfey8w1#