设为首页 加入收藏

TOP

mongodb空间查询之查询单位
2014-11-24 07:45:09 来源: 作者: 【 】 浏览:2
Tags:mongodb 空间 查询 单位
mongodb空间查询之查询单位
1.建立空间索引
www.2cto.com
db.collection.ensureIndex({‘geom.coordinates’:’2d’})
2.空间查询
这里遇到的问题是查询的时候会涉及到范围,那么这个范围的单位是什么?
官方文档提到了该单位使用的是弧度。
所以,比如查询的是 5公里范围某个点周围的信息,则使用如下:(官方推荐的坐标顺序采用的是 [lng,lat]。)
{"geom.coordinates":{$within:{$centerSphere:[[116.314869,39.950785],5*0.621/3963.192]}}}
 1) geom.coordinates 是前面的空间索引字段
2) $within 某个范围内,可以是圆,多边形等
3) $centerSphere[[lng,lat],radius] 
4) radius 是将公里转成英里然后在除以3963.192化成弧度
Ref:
To convert:
distance to radians: divide the distance by the radius of the sphere (e.g. the Earth) in the same units as the distance measurement.
radians to distance: multiply the rad ian measure by the radius of the sphere (e.g. the Earth) in the units system that you want to convert the distance to.
The radius of the Earth is approximately 3963.192 miles or 6378.137 kilometers.
官方资料:http://docs.mongodb.org/manual/core/geospatial-indexes/
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇IN操作符与LIKE子句-各种查询 下一篇PostgreSQL表空间、模式、表、用..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)