【问题标题】:In what units pymongo geo2d aggregate result is returned以什么单位返回 pymongo geo2d 聚合结果
【发布时间】:2017-04-11 15:55:36
【问题描述】:

我的 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。我不太确定它在哪个单位。

从谷歌地图来看,坐标之间的距离是 8,875 公里或 5,515 英里,而 1.3938 不符合这两项要求。从 mongoDB 文档中,我指的是结果不是以弧度返回的。所以我想知道从我的查询响应中引用什么。

谢谢

【问题讨论】:

    标签: python pymongo geospatial


    【解决方案1】:

    以弧度返回的距离。通过乘以 6371 将(非常近似地)弧度转换为公里。

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

    【讨论】:

      猜你喜欢
      • 2021-12-06
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 2021-03-30
      • 2020-09-05
      • 2021-09-20
      相关资源
      最近更新 更多