I have two df as shown below.
df1 = {'Aberdeen Tunnel':[22.2620666,114.1779123]
, 'Lion Rock Tunnel':[22.35134,114.1753917]
, 'Shing Mun Tunnels':[22.3773149,114.1513125]
, 'Tseung Kwan O Tunnel':[22.3191321,114.2440963]
, 'Tsing Sha Highway':[22.343242,114.141755]
, 'Cross Harbour Tunnel':[22.2922422,114.1796539]
, 'Eastern Harbour Crossing':[22.2951813,114.220724]
, 'Western Harbour Crossing':[22.2973088,114.1508622]
, 'Tate\'s Cairn Tunnel':[22.3588556,114.2079283]
, 'Tai Lam Tunnel':[22.3917362,114.0598441]}
df1 = pd.DataFrame(data = df1, index = ['lat','lon'])
df1 = pd.DataFrame.transpose(df1)
print(df1)
df2 = {(22.250559,114.170959),(22.281769,114.180153),(22.336325,114.178978)}
df2 = pd.DataFrame(data = df2, index = ['lat','lon'])
df2 = pd.DataFrame.transpose(df2)
print(df2)
I want to construct a for loop so as to find out from df2, which "Tunnel" is the nearest to the respective coordinates.
I have tried the below to first calculate the respective distance, but it doesn't seem to produce the right output.
for i in df1:
for j in df1:
for h in df2:
for k in df2:
dist = math.hypot(i-h , j-k)
print (dist)