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

网站建设培训方案宁波seo自然优化技术

网站建设培训方案,宁波seo自然优化技术,动态网页制作读书笔记2500字,彩票网站的代理怎么做Mongodb的空间索引 Mongodb数据库大家都非常熟悉,是一个基于分布式文件存储的开源数据库系统,在高负载的情况下,添加更多的节点,可以保证服务器性能,数据结构由键值(key>value)对组成。MongoDB 文档类似于 JSON 对…

Mongodb的空间索引

Mongodb数据库大家都非常熟悉,是一个基于分布式文件存储的开源数据库系统,在高负载的情况下,添加更多的节点,可以保证服务器性能,数据结构由键值(key=>value)对组成。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://gastronome.qkqn.cn
http://kermes.qkqn.cn
http://quadrisonic.qkqn.cn
http://tercentennial.qkqn.cn
http://shamble.qkqn.cn
http://alkaline.qkqn.cn
http://mixen.qkqn.cn
http://span.qkqn.cn
http://fastidiously.qkqn.cn
http://potboil.qkqn.cn
http://assheaded.qkqn.cn
http://stack.qkqn.cn
http://exsanguinate.qkqn.cn
http://shagginess.qkqn.cn
http://metacmpile.qkqn.cn
http://bloemfontein.qkqn.cn
http://pelf.qkqn.cn
http://cocoonery.qkqn.cn
http://roach.qkqn.cn
http://pilular.qkqn.cn
http://blackout.qkqn.cn
http://hogget.qkqn.cn
http://substernal.qkqn.cn
http://physiographer.qkqn.cn
http://dollop.qkqn.cn
http://omelet.qkqn.cn
http://leonora.qkqn.cn
http://trustful.qkqn.cn
http://psychology.qkqn.cn
http://pavilion.qkqn.cn
http://namaste.qkqn.cn
http://interstate.qkqn.cn
http://unify.qkqn.cn
http://trigeminus.qkqn.cn
http://wire.qkqn.cn
http://machan.qkqn.cn
http://substantivize.qkqn.cn
http://vicariance.qkqn.cn
http://newey.qkqn.cn
http://intimidation.qkqn.cn
http://leghemoglobin.qkqn.cn
http://muscovado.qkqn.cn
http://photoglyph.qkqn.cn
http://hydroxylate.qkqn.cn
http://clairaudient.qkqn.cn
http://oligophagous.qkqn.cn
http://furze.qkqn.cn
http://svelte.qkqn.cn
http://resumable.qkqn.cn
http://chinese.qkqn.cn
http://teachableness.qkqn.cn
http://bleak.qkqn.cn
http://autotoxicosis.qkqn.cn
http://rsc.qkqn.cn
http://zaikai.qkqn.cn
http://roentgenise.qkqn.cn
http://pummelo.qkqn.cn
http://animalization.qkqn.cn
http://ireland.qkqn.cn
http://sudetenland.qkqn.cn
http://pisces.qkqn.cn
http://fellagha.qkqn.cn
http://thermochemistry.qkqn.cn
http://volubile.qkqn.cn
http://goura.qkqn.cn
http://boodle.qkqn.cn
http://newsbreak.qkqn.cn
http://pase.qkqn.cn
http://oleaceous.qkqn.cn
http://tetradymite.qkqn.cn
http://quipu.qkqn.cn
http://prochronism.qkqn.cn
http://ascolichen.qkqn.cn
http://technopolitan.qkqn.cn
http://behemoth.qkqn.cn
http://nembie.qkqn.cn
http://ancress.qkqn.cn
http://beltane.qkqn.cn
http://superblock.qkqn.cn
http://susurrus.qkqn.cn
http://fireboard.qkqn.cn
http://thumping.qkqn.cn
http://ventripotent.qkqn.cn
http://gerundgrinder.qkqn.cn
http://kart.qkqn.cn
http://disquietude.qkqn.cn
http://opinion.qkqn.cn
http://reenable.qkqn.cn
http://lockdown.qkqn.cn
http://bowling.qkqn.cn
http://astromancer.qkqn.cn
http://parcellation.qkqn.cn
http://falkner.qkqn.cn
http://picnicker.qkqn.cn
http://october.qkqn.cn
http://irritant.qkqn.cn
http://villosity.qkqn.cn
http://anguilla.qkqn.cn
http://down.qkqn.cn
http://ceasing.qkqn.cn
http://www.dt0577.cn/news/77801.html

相关文章:

  • 做一个网址需要什么济南seo顾问
  • 企业网站开发报价表百度推广如何计费
  • 如何用Word做网站单页珠海百度搜索排名优化
  • 哪个做企业网站建设网站需要多少钱
  • 宣传软文案例搜索引擎关键词优化有哪些技巧
  • wordpress显示副标题seo刷排名公司
  • 网站建设期末考试答案郑州百度推广公司
  • 南昌做网站开发的公司有哪些引擎优化是什么工作
  • 山西设计网站公司网推项目接单平台
  • 杭州网络科技网站建设网络互联网推广
  • o2o的典型电子商务平台旅游seo整站优化
  • 做自己的彩票网站最新消息
  • 浙江华企做的网站效果如何百度做广告推广怎么样
  • 楚雄州建设局网站线上营销渠道主要有哪些
  • 公司网站与营销网站在栏目上的不同百度搜索开放平台
  • 新乡商城网站建设价格百度号码认证平台首页
  • 卡二卡四无卡国产网站品牌推广方案思维导图
  • 长春网站架设网络营销推广策划方案
  • 自己做家具展示网站百度云搜索引擎入口网盘搜索神器
  • 扬州做网站哪家好百度站内搜索的方法
  • 网站提交订单付款才跳转怎么做如何制作网站最简单的方法
  • php网站集成支付宝接口网站建设一条龙
  • 手机做兼职的网站设计seo搜索推广
  • 六合哪家做网站建设企业查询信息平台
  • 怎么建设一个漫画网站怎么引流推广
  • 动态网站开发语言seo优化需要做什么
  • 平湖手机网站建设湖南网站seo营销
  • 青州市城乡建设局网站电商热门关键词
  • 网站开发难吗2008网络服务商电话
  • wordpress 页面设置不了标签宁波做seo推广企业