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. android Qzone的App热补丁热修复技术

    转自:https://mp.weixin.qq.com/s?__biz=MzI1MTA1MzM2Nw==&mid=400118620&idx=1&sn=b4fdd5055731 ...

  2. Linux 用 sftp scp命令 互传文件

    sftp它类似于 ftp, 但它进行加密传输,比FTP有更高的安全性. sftp 是SSH服务的子程序 常用命令 pwd 查看当前工作目录 ls 查看远程当前目录下的所以文件或者目录信息 lls 查看 ...

  3. MySQL常用功能语句分类总结

    C(创建型功能) 创建数据库:CREATE DATABASE 创建用户:CREATE USER 用户名@主机 IDENTIFIED BY 密码; -- 如果想让该用户可以从任意远程主机登陆,可以使用通 ...

  4. Android 权限的由来

    在Android APP开发过程中,某些行为动作需要在AndroidManifest.xml清单文件中进行权限相关的配置: <!-- 增加权限 --> <uses-permissio ...

  5. Oracle/PLSQL: BitAnd Function

    BITAND 函数 本文介绍 Microsoft Excel 中 BITAND 函数的公式语法和用法. 说明 返回两个数的按位“与”. 语法 BITAND( number1, number2) BIT ...

  6. Unity/C#基础复习(3) 之 String与StringBuilder的关系

    参考资料 [1] @毛星云[<Effective C#>提炼总结] https://zhuanlan.zhihu.com/p/24553860 [2] <C# 捷径教程> [3 ...

  7. 从 exe.config 读取appSettings 中的配置数据

    右键解决方案,添加引用--> System.Configuration.dll 在exe.config 中添加数据 <appSettings> <add key=" ...

  8. NetCore入门篇:(十二)在IIS中部署Net Core程序

    一.简介 微软已经为net在iis中的部署提供了良好的支持,在IIS中部署NetCore是一件很容易的事. 二.在IIS中部署Net Core程序 1.微软官方文档有详细说明.进入 2.如果你已经熟悉 ...

  9. OpenStack 虚机网卡的创建过程

    原文链接:https://www.cnblogs.com/potato-chip/p/9127083.html OpenStack虚机网卡的创建过程 OpenStack最基本和常用的操作就是启动虚机. ...

  10. Docker registry 私有仓库镜像查询、删除、上传、下载 shell

    #Docker官方私有仓库registry #官方只提供了API接口,不方便使用,就写了个shell #docker-registry安装配置http://www.cnblogs.com/elvi/p ...