我正在使用 mongo 存储一些地理定位数据,目标是使用 $geointersect 检索它们。具体来说,我将此文档存储在我的数据库中:
{
"loc": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-179.875,
-89.875
],
[
179.875,
-89.875
],
[
179.875,
89.875
],
[
-179.875,
89.875
],
[
-179.875,
-89.875
]
]
]
},
"crs": {
"type": "name",
"properties": {
"name": "urn:x-mongodb:crs:strictwinding:EPSG:4326"
}
},
"type": "Feature",
"properties": {}
},
"_id": "576af8e31d41c87fa1f1d04f"
}
您可能会注意到它几乎涵盖了整个世界。现在,无论我为 $geointersect 查询输入什么坐标,它都不会返回...有人知道为什么吗?
我正在使用的查询示例可能是:
[
{
"loc.geometry": {
"$geoIntersects": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[
13.4307861328125,
41.599013054830216
],
[
13.9801025390625,
41.599013054830216
],
[
13.9801025390625,
41.80407814427234
],
[
13.4307861328125,
41.80407814427234
],
[
13.4307861328125,
41.599013054830216
]
]
]
}
}
}
},
{
"loc": 1
}
]
当然,查询的坐标包含在已保存文档的多边形内(我的意思是......它和世界一样大,呃!)但由于某种原因它没有找到任何匹配......我有点迷路了。
最佳答案
现在正在研究这个。如果多边形是实心的并且大于地球的半球,则 mongo 返回该区域之外的所有内容。在 geoWithin 文档中查看他们的 big poly 和 crs
关于MongoDB 地理相交无法找到大多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38045081/