当前位置: 首页 > news >正文

网站加载速率移动网站 拉新

网站加载速率,移动网站 拉新,wordpress注册错误,平台门户建设Mongodb的空间索引 Mongodb数据库大家都非常熟悉#xff0c;是一个基于分布式文件存储的开源数据库系统#xff0c;在高负载的情况下#xff0c;添加更多的节点#xff0c;可以保证服务器性能#xff0c;数据结构由键值(keyvalue)对组成。MongoDB 文档类似于 JSON 对…Mongodb的空间索引 Mongodb数据库大家都非常熟悉是一个基于分布式文件存储的开源数据库系统在高负载的情况下添加更多的节点可以保证服务器性能数据结构由键值(keyvalue)对组成。MongoDB 文档类似于 JSON 对象。字段值可以包含其他文档数组及文档数组。对与Mongodb还有一个非常重要的功能那就是它的空间索引一般存储每个地点的经纬度的坐标 如果要查询附近的场所则需要建立索引来提升查询效率。 Mongodb专门针对这种查询建立了地理空间索引2d和2dsphere索引 1.首先安装Mongodb数据库在此不再赘述 在开始教程之前呢先介绍一下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.不知道什么意思没关系下面开始讲解 2.2dsphere索引 2dsphere索引是MongoDB最常用的地理空间索引之一用于地球表面类型的地图。允许使用GeoJSON格式指定点、线、多边形。 点可以用形如[longitude,latitude][经度,纬度]的两个元素的数组表示locations字段的名字可以是任意的但是其中的子对象是有GeoJSON指定的不能改变存储的数据格式如下 #点状数据 {coorname : 蘑菇石, locations : {type : Point, coordinates : [108.693809,27.912161]}, types : 标志性建筑物}#线状数据可以由点组成的数组来表示 {name:changjiang,locations:{type:Line,coordinates:[[108.693809,27.912161],[108.693809,27.912161],[108.693809,27.912161]]},types : 标志性建筑物 }#同样多边形也时用点数组表示不同的是type的类型 {name:changjiang,locations:{type:Polygon,coordinates:[[108.693809,27.912161],[108.693809,27.912161],[108.693809,27.912161]]},types : 标志性建筑物 }#注意locations字段里面的key是固定的不要修改否则空间索引无法添加数据添加好之后就要建立空间索引了 #1.使用Mongodb命令添加 db.Periphery_basic.ensureIndex({locations:2dsphere})#2.使用django的ORM添加索引 #在setting中配置mongodb数据库 from mongoengine import connect CONN connect(globalmap).geo_example #创建表 class Periphery_basic(mongoengine.Document):coorname mongoengine.StringField()locations mongoengine.DictField()types mongoengine.StringField() #添加完数据创建索引 Periphery_basic.create_index([(locations,2dsphere)])在Mongodb数据库中产看添加成功没有 #查看索引 db.getCollection(Periphery_basic).getIndexes()#删除集合所有索引 db.getCollection(Periphery_basic).dropIndexes()#删除集合指定索引 db.getCollection(Periphery_basic).dropIndex(索引名)3.2D索引 2d索引也是MongoDB最常用的地理空间索引之一用于游戏地图。2d索引用于扁平表面而不是球体表面。如果用在球体表面上在极点附近会出现大量的扭曲变形一句话就是说2D索引是平面的2dsphere索引是球面的 依然用上面的数据格式添加完之后创建索引 db.Periphery_basic.ensureIndex({locations.coordinates:2d}) #2d索引是要精确到经纬度字段的#django内创建 Periphery_basic.create_index([(locations.coordinates,2d)])4.查询 geoWithIn查询, 查询多边形范围内的点 (适用于两种索引) #命令查询 db.Periphery_basic.find({locations: {$geoWithin: {$geometry: {type : Polygon ,coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]]}}}})#Django查询 Periphery_basic.objects(locations{$geoWithin: {$geometry: {type: Polygon, coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}})#大于单个半球的查询, 需要加入crs db.Periphery_basic.find({locations: {$geoWithin: {$geometry: {type : Polygon ,coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]],crs: {type: name,properties: { name: urn:x-mongodb:crs:strictwinding:EPSG:4326}}}}}})Periphery_basic.objects(locations{$geoWithin: {$geometry: {type: Polygon, coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]],crs: {type: name,properties: {name: urn:x-mongodb:crs:strictwinding:EPSG:4326}}}}})geoIntersects, 图形查询, 交集 (2dsphere索引支持) #命令查询 db.Periphery_basic.find({locations: {$geoIntersects: {$geometry: {type : Polygon ,coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]]}}}}) #django查询 Periphery_basic.objects(locations{$geoIntersects: {$geometry: {type: Polygon, coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}})#大于单个半球的查询, 需要加入crs db.Periphery_basic.find({locations: {$geoIntersects: {$geometry: {type : Polygon ,coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]],crs: {type: name,properties: { name: urn:x-mongodb:crs:strictwinding:EPSG:4326}}}}}})Periphery_basic.objects(locations{$geoIntersects: {$geometry: {type: Polygon, coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]],crs: {type: name,properties: {name: urn:x-mongodb:crs:strictwinding:EPSG:4326}}}}}) $near, 由近道原返回文档的点, 经纬度罗列方式为 [ lng, lat ] 两种索引都支持 #命令查询 db.Periphery_basic.find({locations:{$near:{$geometry: {type: Point, coordinates: [120.665283,31.317678]},$minDistance: 1000,$maxDistance: 5000}}}) #django查询 Periphery_basic.objects(locations{$near:{$geometry: {type: Point, coordinates: [120.665283,31.317678]},$minDistance: 1000,$maxDistance: 5000}})#传统坐标查询 db.Periphery_basic.find({ location : { $near : [120.665283,31.317678], $maxDistance: 10 } } )$nearSphere, 空间距离查询 (两种索引都支持) #命令查询 db.Periphery_basic.find({locations:{$nearSphere:{$geometry: {type: Point, coordinates: [120.665283,31.317678]},$minDistance: 1000,$maxDistance: 5000}}}) #django查询 Periphery_basic.objects(locations{$nearSphere:{$geometry: {type: Point, coordinates: [120.665283,31.317678]},$minDistance: 1000,$maxDistance: 5000}})最大距离内查询 (两种索引都支持) db.Periphery_basic.find({locations: {$nearSphere: [120.665283,31.317678],$maxDistance: 10 } } )$center查询, 圆形查询 (2d索引支持) #平面10公里 db.Periphery_basic.find({locations: { $geoWithin: { $center: [ [120.665283,31.317678], 10 ] } } } ) #django查询 Periphery_basic.objects(locations{$geoWithin: {$center: [ [120.665283,31.317678], 10 ] } } )$centerSphere 查询, 球形查询 (两种索引都支持) #需要把查询的半径转化为弧度 #命令行查询 db.Periphery_basic.find( {locations: { $geoWithin: {$centerSphere: [ [ 120.665283,31.317678 ], 3/3963.2 ] } } } ) #django查询 Village_basic.objects(locations{$geoWithin: {$centerSphere: [[ 120.665283,31.317678 ], 3 / 3963.2]}})$box查询, 先精度后纬度, first lower then upper (2d索引支持) db.Periphery_basic.find({locations: { $geoWithin: {$box: [ [ 0, 0 ], [120.665283,31.317678]]}}})$polygon, 多边形查询 (两种索引都支持) db.Periphery_basic.find({locations: {$geoWithin: { $polygon: [[120.665284,31.317675], [120.665245,31.317612],[120.665265,31.317631]]}}})小结 数据量越来越多的情况下,要想找到合适的坐标并不容易建立空间索引之后数据库自动会按照地理标准进行检索速度上是非常快的目前库中20万条数据每次查询只需零点几秒搜索附近的位置信息是真的快而方便。
http://www.w-s-a.com/news/858052/

相关文章:

  • 不让网站在手机怎么做门户网站 模板之家
  • 网站建设及推广图片wordpress文章摘要调用
  • 手机版网站案例全国信息企业公示系统
  • 模仿别人网站建设银行广州招聘网站
  • 沧州网站建设沧州内页优化
  • 代加工网站有哪些专门做网站关键词排名
  • 郑州做景区网站建设公司软件开发者模式怎么打开
  • 长沙企业网站建设哪家好做app一般多少钱
  • 南宁一站网网络技术有限公司网站开发技术应用领域
  • 公司网站建设方案ppt专业构建网站的公司
  • 深圳网站建设方维网络网站框架设计好后怎么做
  • 合肥网站建设过程网站栏目建设调研
  • 手机访问网站页面丢失北京电商平台网站建设
  • 郑州网站怎么推广中山 网站关键词优化
  • 国外试用网站空间网站建设与管理题目
  • 淄博网赢网站建设网站设计的技术选择
  • 建外贸网站 东莞厦门做网站最好的公司
  • 为您服务网站新网站做百度推广
  • 电子商务免费网站建设网站制作哪个好薇
  • 全面启动门户网站建设中小型企业建设一个网站大概需要多少钱
  • 建网站一般多少钱网站建设上传服务器步骤
  • 手机销售网站怎么做的网站推广优化建设方案
  • 做任务分享赚钱的网站德阳网站建设公司哪家好
  • 云南建设工程质量监督网站wordpress网站导航主题
  • 徐州网站建设哪家好薇手机开源网站代码
  • 更新网站要怎么做呢泰安市58同城招聘网
  • 溧阳网站建设价格企业网站设计费用
  • 我建设的网站打开很慢河北住房和城乡建设厅网站卡
  • 门户网站广告的特点有网站的建设初步定位
  • 建设网站第一步网页建设方案