Swa*_*esh 6 geospatial mongodb geojson 2dsphere
我索引了2dsphere上的字段loc,我无法在Point类型的GeoJson数据上运行geowithin查询.
这是查询:
db.test.find( { loc :
{ $geoWithin :
{ $geometry :
{ type : "Polygon" ,
coordinates : [ [ [-74.6862705412253, 40.42341005] ,
[-75.0846179, 39.9009465 ],
[-74.20570119999999, 41.0167639 ]
]
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
uncaught exception: error: {
"$err" : "Can't canonicalize query: BadValue bad geo query",
"code" : 17287
}
Run Code Online (Sandbox Code Playgroud)
文件结构:
{
"_id" : ObjectId("53d15e7132e7b7978c472e6e"),
"loc" : {
"type" : "Point",
"coordinates" : [ -74.6862705412253, 40.42341005 ]
},
}
Run Code Online (Sandbox Code Playgroud)
索引:
{
"0" : {
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "collab.test"
},
"1" : {
"v" : 1,
"key" : {
"loc" : "2dsphere"
},
"name" : "TestLocationIndex",
"ns" : "collab.test",
"2dsphereIndexVersion" : 2
}
Run Code Online (Sandbox Code Playgroud)
}
但是,$ Polygon在相同的文档上工作正常.我试图理解为什么geowithin不起作用?
Joh*_*ell 13
这是因为您的多边形未关闭,实际上您需要至少四个点才能生成有效多边形,最后重复第一个点,请参阅GeoJSON Polygon文档.不得不说,错误信息可能会更有帮助.对于众所周知的文本(WKT)和众所周知的二进制(WKB)多边形格式也是如此,因此不是GeoJSON的特性.
您的查询应该像这样工作:
db.test.find({loc :
{$geoWithin :
{$geometry :
{type : "Polygon" ,
coordinates : [[[-74.6862705412253, 40.42341005] ,
[-75.0846179, 39.9009465],
[-74.20570119999999, 41.0167639],
[-74.6862705412253, 40.42341005]]]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6092 次 |
| 最近记录: |