我遇到了在多边形(简单框)内匹配项目的问题。我无法弄清楚为什么查询框内的项目没有产生。所以我在这里:
>db.testing.getIndexes();
{
"0" : {
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "test.testing",
"name" : "_id_"
},
"1" : {
"v" : 1,
"key" : {
"point" : "2dsphere"
},
"ns" : "test.testing",
"name" : "2dsphere_index"
}
}
这是我的文件(我测试了不同的格式):
>db.testing.find();
{
"_id" : ObjectId("5439c9c61120c95f4c50a369"),
"point" : {
"lng" : -80.087535,
"lat" : 42.054246
}
}
{
"_id" : ObjectId("5439cc6d1120c95f4c50a36a"),
"point" : {
"type" : "Point",
"coordinates" : [
-80.087535,
42.054246
]
}
}
这是查询:
>db.testing.find({"point": {"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[-80.267831,42.050312],
[-80.267831,45.003652],
[-73.362579,45.003652],
[-73.362579,42.050312],
[-80.267831,42.050312]
]
]
}
}}})
但问题是它返回零结果!
如果你不确定,这一点确实是正方形,而不是复制它:
{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[-80.087535,42.054246]},{"type":"Polygon","coordinates":[[[-80.267831,42.050312],[-80.267831,45.003652],[-73.362579,45.003652],[-73.362579,42.050312],[-80.267831,42.050312]]]}]}
并检查here。
我很困惑,有人可以帮我吗? 提前谢谢!
更新
此外,当我们减少多边形区域时,例如,将这些点找到:
[[-80.159937,42.050312],[-80.05204,42.050312],[-80.05204,42.09646],[-80.159937,42.09646],[-80.159937,42.050312]]
如果需要,我可以提供100个这样的积分。例如,一个更奇怪的问题:
{"type":"Point","coordinates":[-76.537071,42.058731]}
更新
Here是一个带有积分转储的文件(大约700点)。
答案 0 :(得分:1)