我遇到了在多边形(简单框)内匹配项目的问题。我无法弄清楚为什么查询框中的项目没有得到结果。所以我有什么:
>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]]]}]}
并在这里检查。
我很困惑,有人可以帮我解决这个问题吗?
提前致谢!
更新:
此外,当我们减少多边形面积时,会找到这些点,例如:
[[-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]}
更新:
这是一个带有积分收集转储的文件(大约 700 个积分)。