gpt4 book ai didi

python - pymongo geo2d 聚合结果以什么单位返回

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:15 24 4
gpt4 key购买 nike

我的 mongodb 集合中有如下记录

/* 1 */
{
"_id" : ObjectId("58ecf141624bc0798ee5882d"),
"username" : "user.sthlm",
"location" : [
18.0686,
59.3293
]
}

/* 2 */
{
"_id" : ObjectId("58ecf141624bc0798ee5882e"),
"username" : "user.malmo",
"location" : [
13.0038,
55.605
]
}

/* 3 */
{
"_id" : ObjectId("58ecf141624bc0798ee5882f"),
"username" : "user.la",
"location" : [
-118.2437,
34.0522
]
}

“location”是“2dsphere”类型,顺序为[经度,纬度]

现在我使用如下 pymongo 查询来检索给定点之间的距离

(斯德哥尔摩坐标)经度 = 18.0686纬度 = 59.3293

for doc in self.users.aggregate([{"$geoNear": {"near": [longitude, latitude],
"distanceField":"distance",
"distanceMultiplier": 1.0,
"num": int(count),
"spherical": True}}]):

结果如下

  {
"distance": 0,
"username": "user.sthlm"
},
{
"distance": 0.08048218816530191,
"username": "user.malmo"
},
{
"distance": 1.393869662777678,
"username": "user.la"
}

在查询响应中,斯德哥尔摩和洛杉矶之间的距离重新调整为 1.393869662777678。我不太确定它在哪个单位。

从 Google map 来看,坐标之间的距离为 8,875 公里或 5,515 英里,而 1.3938 不符合任何一项要求。从 mongoDB 文档中,我提到结果不是以弧度形式返回的。所以我想知道从我的查询响应中引用什么。

谢谢

最佳答案

距离以弧度形式返回。乘以 6371 将弧度(非常近似)转换为公里。

6371 * 1.393 = 8874 公里,符合预期。

关于python - pymongo geo2d 聚合结果以什么单位返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43350843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com