MongoDB采用geoJson格式来存储常见的点,线,面的几何信息.
点:db.points.insert({"pt":{type:"Point",coordinates:[10,10]}})
线:db.lines.insert({"ln":{type:"LineString",coordinates:[[10,10],[20,20]]}})
面:db.polygons.insert({"pg":{type:"Polygon",coordinates:[[[5,5],[5,15],[15,15],[15,5],[5,5]]]}})
常见的空间查找操作:
1.包含$geoWithin
db.points.find({"pt":{$geoWithin:{$geometry:{type:"Polygon",coordinates:[[[5,5],[5,15],[15,15],[15,5],[5,5]]]}}}})
圆形查询: db.points.find({"pt":{$geoWithin:{$centerSphere:[[6,6](圆心),2(半径)]}})
2.相交$geoIntersects
db.lines.find({"ln":{$geoIntersects:{$geometry:{type:"Polygon

本文介绍了MongoDB中如何使用geoJson格式存储点、线、面的几何信息,并详细阐述了包含查询$geoWithin、相交查询$geoIntersects、点查询$near以及周边查询geonear的操作方法,同时提到了建立2dsphere索引的重要性。
最低0.47元/天 解锁文章
3940

被折叠的 条评论
为什么被折叠?



