我建议您使用 pyproj 而不是 geopy。 geopy 依赖于在线服务,而 pyproj 是本地的(这意味着它会更快并且不会依赖于 Internet 连接)并且其方法更透明(例如,参见 here),它们基于本质上是基础的 Proj4 代码库所有开源 GIS 软件,可能还有您会使用的许多 Web 服务。
#!/usr/bin/env python3
import pandas as pd
import numpy as np
from pyproj import Geod
wgs84_geod = Geod(ellps='WGS84') #Distance will be measured on this ellipsoid - more accurate than a spherical method
#Get distance between pairs of lat-lon points
def Distance(lat1,lon1,lat2,lon2):
az12,az21,dist = wgs84_geod.inv(lon1,lat1,lon2,lat2) #Yes, this order is correct
return dist
#Create test data
lat1 = np.random.uniform(-90,90,100)
lon1 = np.random.uniform(-180,180,100)
lat2 = np.random.uniform(-90,90,100)
lon2 = np.random.uniform(-180,180,100)
#Package as a dataframe
df = pd.DataFrame({'lat1':lat1,'lon1':lon1,'lat2':lat2,'lon2':lon2})
#Add/update a column to the data frame with the distances (in metres)
df['dist'] = Distance(df['lat1'].tolist(),df['lon1'].tolist(),df['lat2'].tolist(),df['lon2'].tolist())
PyProj 有一些文档here。