我试图用SRID(32148)计算两个位置之间的距离,以下是我的两点
Point-1:
Lat:46.489767 Long:-119.043221
Point-2:
Lat:47.610902 Long:-122.336422这网站称,以英里b/w为单位的距离是173.388,但是从下面的代码来看,我得到的结果是0.002161632093865483。
这是我正在使用的代码
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这是附加调试结果的更多细节。

关于为什么我的结果如此不同,有什么建议吗?
更新:
我尝试使用以下代码使用SRID 4326转换该位置。然而,结果仍然不正确。

发布于 2018-11-01 08:20:48
您似乎使用了lon / lat坐标作为SRID(32148)坐标;您需要对它们进行转换。
这个不正确的查询会给出结果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)https://stackoverflow.com/questions/53096052
复制相似问题