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 ...
随机推荐
- hdu 4996 1~n排列LIS值为k个数
http://acm.hdu.edu.cn/showproblem.php?pid=4996 直接贴bc题解 按数字1-N的顺序依次枚举添加的数字,用2N的状态保存在那个min数组中的数字,每次新添加 ...
- java实现WC项目
个人项目:WC wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有wc.exe 的功能,并加以扩充,给出某程序设计语言源文件的字符数.单 ...
- [label][翻译][JavaScript Regular Expression]JavaScript Regular Expressions
原文:http://www.javascriptkit.com/javatutors/re.shtml 校验用户的输入是每一个软件开发者的必须要做的事情. 正则表达式与模式 如何在JavaScript ...
- Win10系统下编译OSG3.4
环境说明 1.Win10专业版.64位: 2.VS2012旗舰版:QT5.2.0: 3.cmake-3.9.0.64位: 资源准备 1.OSG3.4源码包 http://trac.opensceneg ...
- java多线程 —— 两种实际应用场景模拟
最近做的偏向并发了,因为以后消息会众多,所以,jms等多个线程操作数据的时候,对共享变量,这些要很注意,以防止发生线程不安全的情况. (一) 先说说第一个,模拟对信息的发送和接收.场景是这样的: 就像 ...
- Web app制作细节:web app互动制作技巧
Google .微软.苹果三大巨头紧锣密鼓地在web app的研发产品领域圈地设岗,并试图建立以自己为中心的”云“服务平台,企图在web app时代到来的时候充当霸主.本文将围绕web app的制作, ...
- echarts呈现数据表图形
讲一下echarts的用法,列举了两个图表,一个是单柱图,一个是多柱图,至于饼状图,只许更改echarts的类型就好了 一.首先是要两个div,用来存放两个图表 <div class=" ...
- 初探Angular_02 感受添加组件
首先把目光聚焦在app这个文件夹里面 1.app.module.ts 这个文件是angular根模块,告诉Angular如何组装应用 // 浏览器解析的模块 import { BrowserModul ...
- 数据库如何从SQL server转换到SQLite
我之前用的是SQL server数据库,但是客户那里觉得安装这个大的数据库比较卡,说是导致蓝屏了,硬往SQL server上赖,没有办法客户是上帝么,给他换个小点的数据库吧!考虑Access,不行这个 ...
- Axure学习了解
我这次介绍的原型设计工具为Axure 一.区域介绍 这是主界面: 左上区域显示原型的各个界面,可以添加新界面: 左中包含各种原型设计所包含的组件,例如文本框,图片等: 左下是各种模板,模板由自己设计, ...