mongodb-地理坐标存储查询
mongodb可支持空间地理搜索:
查询器
$geoWithin Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. replaces$withinwhich is deprecated.
$geoIntersects Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
$near Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near.
$nearSphere Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
查询参数:
$geometry |
Specifies a geometry in GeoJSON format to geospatial query operators. |
$minDistance |
Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. |
$maxDistance |
Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphereand 2d indexes support $maxDistance. |
$center |
Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. |
$centerSphere |
Specifies a circle using either legacy coordinate pairs or GeoJSON format for $geoWithin queries when using spherical geometry. The 2dsphere and 2d indexes support $centerSphere. |
$box |
Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. |
$polygon |
Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports$center. |
$uniqueDocs |
Deprecated. Modifies a $geoWithin and $near queries to ensure that even if a document matches the query multiple times, the query returns the document once. |
1, geoWithIn查询, 替代以前的wihin查询, 查询多边形范围内的点
db.places.find(
{
loc: {
$geoWithin: {
$geometry: {
type : "Polygon" ,
coordinates: [ [ [ , ], [ , ], [ , ], [ , ] ] ]
}
}
}
}
)
对于大于单个半球的查询, 需要加入crs
db.places.find(
{
loc: {
$geoWithin: {
$geometry: {
type : "Polygon" ,
coordinates: [
[
[ -, ], [ -, ], [ -, - ], [ , - ], [ , ], [ -, ]
]
],
crs: {
type: "name",
properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
}
}
}
}
}
)
2, geoIntersects, 图形查询, 交集
db.places.find(
{
loc: {
$geoIntersects: {
$geometry: {
type: "Polygon" ,
coordinates: [
[ [ , ], [ , ], [ , ], [ , ] ]
]
}
}
}
}
)
查询大于半个半球的
db.places.find(
{
loc: {
$geoIntersects: {
$geometry: {
type : "Polygon",
coordinates: [
[
[ -, ], [ -, ], [ -, - ], [ , - ], [ , ], [ -, ]
]
],
crs: {
type: "name",
properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
}
}
}
}
}
)
3, $near, 由近道原返回文档的点, 经纬度罗列方式为 [ lng, lat ]
需要创建空间索引
2dsphere index if specifying a GeoJSON point,
2d index if specifying a point using legacy coordinates.
db.places.ensureIndex( { loc : "2d" } ) //应该是固定格式
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: ,
$maxDistance:
}
}
}
)
使用传统坐标查询:
db.legacy2d.find(
{ location : { $near : [ -73.9667, 40.78 ], $maxDistance: 0.10 } }
)
4, $nearSphere, 空间距离查询
同样需要建立空间索引
2dsphere index for location data defined as GeoJSON points
2d index for location data defined as legacy coordinate pairs. To use a 2d index on GeoJSON points, create the index on the coordinates field of the GeoJSON object.
db.places.find(
{
location: {
$nearSphere: {
$geometry: {
type : "Point",
coordinates : [ -73.9667, 40.78 ]
},
$minDistance: ,
$maxDistance:
}
}
}
)
最大距离内查询:
db.places.find( {
loc: { $near: [ - , ], $maxDistance: }
} )
5, $center查询, 圆形查询
db.places.find(
{ loc: { $geoWithin: { $center: [ [-, 40.74], ] } } }
)
6, $centerSphere 查询, 球星查询
db.places.find( {
loc: { $geoWithin: { $centerSphere: [ [ -, ], /3963.2 ] } }
} )
7, $box查询, 先精度后纬度, first lower then upper
db.places.find( {
loc: { $geoWithin: { $box: [ [ , ], [ , ] ] } }
} )
8, $polygon, 多边形查询
db.places.find(
{
loc: {
$geoWithin: { $polygon: [ [ , ], [ , ], [ , ] ] }
}
}
)
mongodb的空间位置查询
我是勤劳的搬运工: -> https://docs.mongodb.com/manual/reference/operator/query-geospatial/
mongodb-地理坐标存储查询的更多相关文章
- mongodb的存储引擎
mongodb版本为3.4 mongodb存储引起的一些概述 存储引擎是MongoDB的核心组件,负责管理数据如何存储在硬盘和内存上.从MongoDB 3.2 版本开始,MongoDB 支持多数据存储 ...
- morphia 框架 mongodb内嵌查询
mongodb中存储的文档格式如下,实现查询fromdata下did和dvid为指定值的数据 { "_id": { "$oid": "553f4a9f ...
- mongodb的高级查询
db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false]) 添加用户 db.auth(usrename,passwor ...
- mongodb 高级聚合查询
mongodb高级聚合查询 在工作中会经常遇到一些mongodb的聚合操作,特此总结下.mongo存储的可以是复杂类型,比如数组.对象等mysql不善于处理的文档型结构,并且聚合的操作也比mysq ...
- MongoDB如何存储数据
想要深入了解MongoDB如何存储数据之前,有一个概念必须清楚,那就是Memeory-Mapped Files. Memeory-Mapped Files 下图展示了数据库是如何跟底层系统打交道的. ...
- MongoDB 覆盖索引查询
MongoDB 覆盖索引查询 官方的MongoDB的文档中说明,覆盖查询是以下的查询: 所有的查询字段是索引的一部分 所有的查询返回字段在同一个索引中 由于所有出现在查询中的字段是索引的一部分, Mo ...
- MongoDB 入门之查询(find)
MongoDB 入门之查询(find) 1. find 简介 (1)find的第一个参数决定了要返回哪些文档. 空的查询文档会匹配集合的全部内容.默认就是{}.结果将批量返回集合c中的所有文档. db ...
- MongoDB的存储结构及对空间使用率的影响
MongoDB的存储结构及对空间使用率的影响 使用MongoDB一段时间的同学肯定会发现,MongoDB往往会占用比实际数据大小多不少空间的问题.如果利用db.stats()命令去查看,会发现Mong ...
- MongoDB数据库中查询数据(下)
MongoDB数据库中查询数据(下) 在find中,options参数值为一个对象,用来设置查询数据时使用的选项,下面我们来对该参数值对象中可以使用的属性进行介绍: 1. fields; 该属性值为一 ...
- 在MongoDB数据库中查询数据(上)
在MongoDB数据库中查询数据(上) 在MongoDB数据库中,可以使用Collection对象的find方法从一个集合中查询多个数据文档,find方法使用方法如下所示: collection.fi ...
随机推荐
- Python学习-30.Python中的元组(tuple)
元组使用()定义,元组一旦定义就无法修改. 元组的索引方式同列表,也是使用[]. 元组也可以进行切片操作,使用方式同列表一样. 可以说,一个没法修改的列表就是元组. 在没有修改操作的情况下,应尽可能使 ...
- fleet中service之间的依赖关系
最近有人在topcoder上提出使用fleet在集群上部署service时有时候会发现,当启动依赖于整个集群服务的service时,只会检查那个service所在机器的依赖关系,这样就会造成一些问题, ...
- spring mvc配置ObjectMapper忽略无法识别的字段,以及一些博客推荐
通过Spring的MethodInvokingFactoryBean类实现的调用configure方法,此方法返回调用该方法的本身实例. 配置完毕后,可以在spring mvc的消息处理器中使用,为了 ...
- Replication--查看未分发命令和预估所需时间
当复制有延迟时,我们可以使用复制监视器来查看各订阅的未分发命令书和预估所需时间,如下图: 但是当分发和订阅数比较多的时候,依次查看比较费时,我们可以使用sys.sp_replmonitorsubscr ...
- ftp服务器问题
最近ftp服务器迁移,遇到了521问题,可以尝试以下几种方法: 1,服务器管理器->Web服务器->FTP服务器安装完: 2,检查相应文件夹的权限是否足够, 3,检查ft ...
- 【ocp新题】OCP 12c 062认证考试出现大量新题-8
8. Which are two ways for a database service to be recognized by a listener in Oracle Database 12c? ...
- jzoj100044
完全背包問題 我們可以將數組內每個元素看成一個物品,這樣問題就轉化成: 現有n個物品,每個物品可以取a[i]~b[i]個,價值為d[i],費用為c[i],問怎麼樣取讓費用為0且價值最大 我們可以先每種 ...
- 双11,自动领取优惠券 js 代码
http://www.zhihu.com/question/36426051/answer/67690322 本来我不熟悉 js,正好研究一下 (function(window, document) ...
- window7下Python安装
去python官网下载软件,https://www.python.org. 选择dowloads-->windows,选择稳定版python3.5.2,x86表示32位操作系统,x86-64表示 ...
- react.js 点击事件传递参数的方法
<button onClick={this.handleClick.bind(this, props0, props1, ...}></button> handleClick( ...