Python 通过转换为utm的Lat/lon距离计算得出的结果与使用近似方法得出的结果不同

Python 通过转换为utm的Lat/lon距离计算得出的结果与使用近似方法得出的结果不同,python,distance,geo,utm,pyproj,Python,Distance,Geo,Utm,Pyproj,在python中,我有两种计算地理参考坐标之间距离的方法: from pyproj import Proj import math def calc_distance(lat1, lon1, lat2, lon2): """ Calculate the great circle distance between two points on the earth (specified in decimal degrees) """ # convert dec

在python中,我有两种计算地理参考坐标之间距离的方法:

from pyproj import Proj
import math

def calc_distance(lat1, lon1, lat2, lon2):
    """
    Calculate the great circle distance between two points
    on the earth (specified in decimal degrees)
    """
    # convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])

    # haversine formula
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
    c = 2 * math.asin(math.sqrt(a))
    km = 6371 * c

    return km

def calc_distance_convert_utm(lat1, lon1, lat2, lon2):
    myProj = Proj("+proj=utm +zone=42, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs")

    # convert to utm 
    utm_x1, utm_y1 = myProj(lat1, lon1)
    utm_x2, utm_y2 = myProj(lat2, lon2)

    diff_x = abs(utm_x1 - utm_x2)
    diff_y = abs(utm_y1 - utm_y2)

    distance = math.sqrt(diff_x**2 + diff_y**2)

    return distance
我用以下值调用它:

lat1 = 34.866527
lon1 = 69.674606
lat2 = 34.864990
lon2 = 69.657655
print "approximation method: ", calc_distance(lat1, lon1, lat2, lon2)
print "converting to utm method: ", calc_distance_convert_utm(lat1, lon1, lat2, lon2)
但是,如果比较结果,会得到两个不同的值:

approximation method:  1.55593476881
converting to utm method:  1928.21537269
请注意,第一种方法以公里为单位返回距离,而第二种方法以米为单位返回距离。 我将结果与你可以在网上找到的距离计算器进行了比较,第一种方法(近似法)似乎是“更正确”的答案,因为这是大多数在线计算器返回的值。我想知道,为什么第二种方法(首先转换为utm)没有返回更相似的结果(比如1555.9347…)。我有一个几乎0.5公里的差距,这对我来说似乎差不多

我做错什么了吗? 感谢您的帮助!谢谢

我发现了错误。。。 在utm转换方法中,我在转换过程中切换了lat/lon值。应该是:

utm_x1, utm_y1 = myProj(lon1, lat1)
utm_x2, utm_y2 = myProj(lon2, lat2)