我正在查询一个多边形,以检查一个点是否在其中,但没有返回结果。我在mongo shell中:(MongoDB shell版本:3.2.6)
db.restPolygons.find();
{
"_id" : ObjectId("586e663175c32828be59e3a9"),
"zoneCoordinates" : {
"type" : "Polygon",
"coordinates" : [
[ 2, 0 ],
[ 6, 0 ],
[ 6, 2 ],
[ 2, 2 ],
[ 2, 0 ]
]
}
}
db.restPolygons.find({
"zoneCoordinates": {
"$geoIntersects": {
"$geometry": {
"type": "Point",
"coordinates": [3 ,1]
}
}
}
}).count();
0
最佳答案
您的多边形无效,它在坐标
字段中缺少封闭数组的级别。这个应该可以工作:
> db.geo.find()
{
"_id": ObjectId("586e663175c32828be59e3a9"),
"zoneCoordinates": {
"type": "Polygon",
"coordinates": [
[
[2, 0],
[6, 0],
[6, 2],
[2, 2],
[2, 0]
]
]
}
}
> db.geo.find({
"zoneCoordinates": {
"$geoIntersects": {
"$geometry": {
"type": "Point",
"coordinates": [3 ,1]
}
}
}
}).count()
1
您可以在 GeoJSONLint 中检查 GeoJSON 对象的有效性
关于mongodb - $geoIntersects 没有返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41489245/