mongodb可支持空间地理搜索:

查询器

$geoWithin       Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. replaces $within which 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-地理坐标存储查询的更多相关文章

  1. mongodb的存储引擎

    mongodb版本为3.4 mongodb存储引起的一些概述 存储引擎是MongoDB的核心组件,负责管理数据如何存储在硬盘和内存上.从MongoDB 3.2 版本开始,MongoDB 支持多数据存储 ...

  2. morphia 框架 mongodb内嵌查询

    mongodb中存储的文档格式如下,实现查询fromdata下did和dvid为指定值的数据 { "_id": { "$oid": "553f4a9f ...

  3. mongodb的高级查询

    db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false])  添加用户 db.auth(usrename,passwor ...

  4. mongodb 高级聚合查询

    mongodb高级聚合查询   在工作中会经常遇到一些mongodb的聚合操作,特此总结下.mongo存储的可以是复杂类型,比如数组.对象等mysql不善于处理的文档型结构,并且聚合的操作也比mysq ...

  5. MongoDB如何存储数据

    想要深入了解MongoDB如何存储数据之前,有一个概念必须清楚,那就是Memeory-Mapped Files. Memeory-Mapped Files 下图展示了数据库是如何跟底层系统打交道的. ...

  6. MongoDB 覆盖索引查询

    MongoDB 覆盖索引查询 官方的MongoDB的文档中说明,覆盖查询是以下的查询: 所有的查询字段是索引的一部分 所有的查询返回字段在同一个索引中 由于所有出现在查询中的字段是索引的一部分, Mo ...

  7. MongoDB 入门之查询(find)

    MongoDB 入门之查询(find) 1. find 简介 (1)find的第一个参数决定了要返回哪些文档. 空的查询文档会匹配集合的全部内容.默认就是{}.结果将批量返回集合c中的所有文档. db ...

  8. MongoDB的存储结构及对空间使用率的影响

    MongoDB的存储结构及对空间使用率的影响 使用MongoDB一段时间的同学肯定会发现,MongoDB往往会占用比实际数据大小多不少空间的问题.如果利用db.stats()命令去查看,会发现Mong ...

  9. MongoDB数据库中查询数据(下)

    MongoDB数据库中查询数据(下) 在find中,options参数值为一个对象,用来设置查询数据时使用的选项,下面我们来对该参数值对象中可以使用的属性进行介绍: 1. fields; 该属性值为一 ...

  10. 在MongoDB数据库中查询数据(上)

    在MongoDB数据库中查询数据(上) 在MongoDB数据库中,可以使用Collection对象的find方法从一个集合中查询多个数据文档,find方法使用方法如下所示: collection.fi ...

随机推荐

  1. 四则运算 Java 实现 刘丰璨,王翠鸾

    四则运算 GitHub仓库 功能实现 [x] 使用 -n 参数控制生成题目的个数,并且根据解空间限制用户设定的范围(如 range == 2 时,用户却要求生成 10000 道题目,这明显不合理) [ ...

  2. inline函数的作用

    (一)inline函数(摘自C++ Primer的第三版) 在函数声明或定义中函数返回类型前加上关键字inline即把min()指定为内联. inline int min(int first, int ...

  3. C# 读取Excel表格内容,以及NPOI的使用

    在实际的开发中,我们可能需要读写word或者Excel的内容,在我开发的项目中,需要读取Excel的内容,并将相对应的内容存储到数据库中,这里简单跟大家分享一下,希望能够帮助一些人. 我相信在读写wo ...

  4. update from用法

    from:https://www.cnblogs.com/zerocc/archive/2011/11/01/2231841.html update 表名 SET  更新字段 FROM 更新表名(多个 ...

  5. BitAdminCore框架更新日志20180531

    索引 NET Core应用框架之BitAdminCore框架应用篇系列 框架演示:http://bit.bitdao.cn 框架源码:https://github.com/chenyinxin/coo ...

  6. Ruby for Sketchup 贪吃蛇演示源码(naive_snake)

    sketchup是非常简单易用的三维建模软件,可以利用ruby 做二次开发, api文档 http://www.rbc321.cn/api 今天在su中做了一款小游戏 贪吃蛇,说一下步骤 展示 主要思 ...

  7. In file included from adlist.c:34:0: zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录

    问题: In file included from adlist.c:34:0:zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录 解决: make ...

  8. 没有过的题QAQ

    持续更新...纪念一下我的高分暴力...(好丢人啊qwq) NOI2014 动物园 80pts 用倍增暴力跳nxt数组 #include<iostream> #include<cst ...

  9. 《Python黑帽子:黑客与渗透测试编程之道》 Windows下木马的常用功能

    有趣的键盘记录: 安装pyHook: http://nchc.dl.sourceforge.net/project/pyhook/pyhook/1.5.1/pyHook-1.5.1.win32-py2 ...

  10. spring JdbcTemplate批量插入以及单个插入时获取id

    1. 批量更新插入 jdbcTemplate.batchUpdate(String sql, List<Object[]> batchArgs) Object[]数组的长度为每条记录的参数 ...