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. Oracle sql 优化の索引监控

    1.监视索引是否使用 除了主键是完整性约束而自动变为索引外,创建普通索引的目的就是为了提高查询速度,如果我们创建了索引而没有被使用,那么这些不被使用的索引将起到阻碍性能的作用. 语法: --检查某个索 ...

  2. WebApi使用JWT认证(一)

    这是第一部:先实现NetFramework上的WebApi使用JWT认证 1.VS新建一个WebApi项目 2.项目右键----管理Nuget程序包----找到JWT,然后安装 3.Model文件夹下 ...

  3. Win10系统下编译GEOS3.6.2

    环境说明 1.Win10专业版.64位: 2.VS2012旗舰版: 3.cmake-3.9.0.64位: 资源准备 GEOS管网(http://trac.osgeo.org/geos)下载3.4.3版 ...

  4. LeetCode150:Evaluate Reverse Polish Notation

    题目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are + ...

  5. NET 集合分页查询

    参数: var list = new List<int>(); // 集合 ; // 总数量 ; // 每页查询数量 第一种: ? totalCount / pageSize : tota ...

  6. C#: 获取当前路径不要用Environment.CurrentDirectory

    网上大把文章写到C#获取当前路径的方法如下: // 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. Syste ...

  7. [.net 多线程]线程基础

    一.线程状态 1.新建状态(New):         当用new操作符创建一个线程时, 例如new Thread(r),线程还没有开始运行,此时线程处在新建状态. 当一个线程处于新生状态时,程序还没 ...

  8. 查看.net frameword版本

    官方答案. 具体步骤如下: 1.打开注册表(Win+R,输入regedit): 2.输入注册表路径:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framewor ...

  9. 使用datepicker日期插件

    使用datepicker日期插件 在引入<jquery.js> <bootstrap.js><datepicker.js>之后 引用<bootstrap.cs ...

  10. 错误:Parameter '0' not found.Available parameters are [arg1, arg0, param1, param2]的解决方法

    调用的方法: List<Card> temp = cardService.queryRepeat(Type,shop); xml: <select id="queryRep ...