【问题标题】:define geo index in ArangoDB在 ArangoDB 中定义地理索引
【发布时间】:2016-05-14 10:43:28
【问题描述】:

我有一个如下的数据结构。如何为该结构定义地理索引?

{
  "currentGeoLocation": {
    "latitude": -10,
    "longitude": 1
  }
}

我尝试了这些命令: 1-

db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation[latitude]","currentGeoLocation[longitude]" ] }); 

2-

 db.test.ensureIndex({ type: "geo", fields: [ "currentGeoLocation.latitude","currentGeoLocation.longitude" ] }); 

但我认为没有一个可以正常工作。因为在我搜索最近的项目后,我得到了 []。 有什么问题?

【问题讨论】:

  • 这些答案对你有用吗?如果是,您能否将其中最好的标记为“已接受”?如果没有,缺少什么?您愿意分享您的实际解决方案吗?

标签: geolocation location arangodb aql


【解决方案1】:

您的第二个索引创建是正确的。

必须知道,纬度和经度实际上并不是千米单位。将[-10, 1] 输入a distance calculator(这也是一个关于计算细节的好读物)告诉你它的1117 km 远离[0,0]。由于ArangoDB中半径的单位是m,所以数字变大了。

在实际地点搜索肯定会找到您的物品:

db._query('FOR item IN WITHIN(test, -10, 1, 1) RETURN item').toArray()

但是,从[0,0] 搜索需要更大的半径:

db._query('FOR item IN WITHIN(test, 0, 0, 1200000) RETURN item').toArray()
[ 
  { 
    "_key" : "840", 
    "_id" : "test/840", 
    "_rev" : "840", 
    "currentGeoLocation" : { 
      "latitude" : -10, 
      "longitude" : 1 
    } 
  } 
]

【讨论】:

  • 遇到同样的问题,如果坐标像这个问题一样嵌套,则查询不起作用。但是,如果我们在数据未嵌套的集合上定义地理索引,则查询有效。
【解决方案2】:

接上一个回答,你是用arangosh接口还是arangodb js?

我问,因为 arangodb js 界面不同。在这种情况下,您会看到如下内容:

db.collection('testnodes').createGeoIndex(['currentGeoLocation.latitude', 'currentGeoLocation.longitude'])

此外,arangodb 还附带了许多非常有用的地理定位功能(附近、内部等),这些功能具有自动计算距离的辅助功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多