2021年4月9日星期五

How to create distance table using geodesic

I'm calculating with Python. Let's say i have this kind of DataFrame where it consists of long lat of some points

import pandas as pd  dfa=pd.DataFrame(([1,2],[1,3],[1,1],[1,4]), columns=['y','x'])  

before, i used distance matrix from geopy and create another DataFrame with this code. but it seems that it can't precisely calculate the distance between points (with long lat)

from scipy.spatial import distance_matrix  pd.DataFrame(distance_matrix(dfa.values, dfa.values), index=dfa.index, columns=dfa.index)  

Do you think it's possible to change the calculation with geodesic?

from geopy.distance import geodesic  pd.DataFrame(geodesic(dfa.values[0], dfa.values[0]).kilometers, index=dfa.index, columns=dfa.index)    # i don't know how to change [0] adjusted to column and index  

any suggestion?

https://stackoverflow.com/questions/67030182/how-to-create-distance-table-using-geodesic April 10, 2021 at 10:06AM

没有评论:

发表评论