dev*_*v ツ 4 geospatial mongodb mongo-java
mongoDB $geoWithin和$geoIntersects运营商有什么区别?
如果我找坐标(使用默认坐标参照系),$geoWithin以及$geoIntersects将返回相同的结果.
如果我错了,请纠正我.
任何简单的用例来理解差异将不胜感激.
wdb*_*ley 10
选择地理空间数据与指定GeoJSON对象相交的文档; 即数据和指定对象的交集是非空的.这包括数据和指定对象共享边缘的情况.
来自$ geoWithin:
选择具有完全在指定形状内的地理空间数据的文档.
请看以下示例:
> db.test.drop()
> var poly1 = { "type" : "Polygon", "coordinates" : [[[0, 0], [3, 0], [0, 3], [0, 0]]] }
> var poly2 = { "type" : "Polygon", "coordinates" : [[[1, 1], [2, 1], [1, 2], [1, 1]]] }
// poly1 is a similar triangle inside poly2
> var poly3 = { "type" : "Polygon", "coordinates" : [[[1, 0], [-2, 0], [1, 3], [1, 0]]] }
// poly3 is poly1 flipped around its "vertical" edge, then bumped over one unit, so it intersects poly1 but is not contained in it
> db.test.insert({ "loc" : poly2 })
> db.test.insert({ "loc" : poly3 })
> db.test.ensureIndex({ "loc" : "2dsphere" })
> db.test.find({ "loc" : {
"$geoIntersects" : {
"$geometry" : poly1
}
} })
// poly2 and poly3 returned
> db.test.find({ "loc" : {
"$geoWithin" : {
"$geometry" : poly1
}
} })
// poly2 returned
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2661 次 |
| 最近记录: |