用纵向相关法计算两点间的距离时,结果相差很大

2024-10-01 07:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用SRID(32148)计算两个位置之间的距离 这是我的两点

Point-1:
Lat:46.489767 Long:-119.043221
Point-2:
Lat:47.610902 Long:-122.336422

This网站声明这两点的距离(以英里为单位)是173.388,但是从下面的代码中,我得到的结果是0.00216132093865483

这是我正在使用的代码

    employeeloc = modelEmployee.objects.filter(user__first_name="adam")[0].location
    employerloc = modelEmployer.objects.filter(user__first_name="adam")[0].location
    meters = employerloc.distance(employeeloc)
    #Caluclate in miles
    dobj = Distance(m=meters)
    mi = dobj.mi

这是一个更详细的调试结果附加 enter image description here 为什么我的结果如此不同,有什么建议吗

更新:

我尝试使用srid4326转换位置,但是结果仍然不正确

enter image description here


Tags: 代码name距离objectslocationfilterlongpoint
1条回答
网友
1楼 · 发布于 2024-10-01 07:29:29

您似乎使用了lon/lat坐标作为SRID(32148)坐标;你需要改变他们

由于坐标与SRID不匹配,此不正确的查询的结果为3.47m:

select 
st_distance(
st_setsrid(st_point(-122.336422,47.610902),32148),
st_setsrid(st_point(-119.043221,46.489767),32148))
  3.47880964046985

此查询将提供预期的173.71 mi结果:

select 
st_distance(
st_transform(st_setsrid(st_point(-122.336422,47.610902),4326),32148),
st_transform(st_setsrid(st_point(-119.043221,46.489767),4326),32148))

 279558.106935732m (=173.71mi)

这与这个查询的结果类似:

select 
st_distance(
st_setsrid(st_point(-122.336422,47.610902),4326)::geography,
st_setsrid(st_point(-119.043221,46.489767),4326)::geography)

 279522.55326056 m (= 173.69 mi)

相关问题 更多 >