存储MongoDb的经纬度数据实现空间索引
作者:matrix 发布时间:2018-11-26 分类:零零星星
数据存储
mongoDb自带了地理空间索引,使用2dsphere
索引类型 可以存储GeoJSON格式数据 指定点、线和多边形。
mongoDb数据
{
"_id" : ObjectId("5bf04829c6671064f9039dd0"),
"order_info" : {
"survey_coordinate" : {
"type" : "Point",
"coordinates" : [
105.431,
42.009
],
"name":"XXXXX街道办"
}
}
}
order_info.survey_coordinate字段为需要存储的数据
type:Point 点
coordinates 经纬度信息: [longitude, latitude]代表[经度, 纬度]
name为附加自定的存储名称字段
参考:
http://geojson.org/
mongodb官方文档:https://docs.mongodb.com/manual/reference/geojson/
添加索引
- 手动创建
db.order.ensureIndex( {"order_info.survey_coordinate" : "2dsphere"} ) //联合索引 如: db.order.createIndex( {"order_info.survey_coordinate" : "2dsphere","category" : -1, name: 1 } ) // 指定索引名称:db.order.createIndex( {"order_info.survey_coordinate" : "2dsphere"},{name:"locc"} )
参考:
http://www.runoob.com/mongodb/mongodb-indexing.html -
代码创建
后来专门去找了下php下代码的操作,翻看各种TP文档无果,还是Google靠谱。php官方文档中
ThinkPHP5.0 参考$mongodb;//mongodb对象为 think\db\Connection https://www.kancloud.cn/manual/thinkphp5/167865 //创建索引 $command = new \MongoDB\Driver\Command([ 'createIndexes' => 'order',//给哪个集合创建索引 'indexes' => [[ 'name' => 'order_info_loc_2dsphere',//索引名称 'key' => ['order_info.survey_coordinate' => '2dsphere']//索引的字段 索引类型 ]] ]); $result = $mongodb->command($command); //首次创建返回数据 // /vagrant/saasSystem/thinkphp/library/think/Debug.php:193: //array (size=1) // 0 => // array (size=4) // 'createdCollectionAutomatically' => boolean false // 'numIndexesBefore' => int 1 // 'numIndexesAfter' => int 2 // 'ok' => float 1 //0.322759s ShowPageTrace //重复创建返回数据 // /vagrant/saasSystem/thinkphp/library/think/Debug.php:193: //array (size=1) // 0 => // array (size=5) // 'createdCollectionAutomatically' => boolean false // 'numIndexesBefore' => int 2 // 'numIndexesAfter' => int 2 // 'note' => string 'all indexes already exist' (length=25) // 'ok' => float 1 halt($result);
参考:
http://php.net/manual/en/mongocollection.createindex.php#119584
数据查询
-
runCommand执行
db.runCommand( { geoNear: "order" , //存在2dsphere索引的集合名称 near: { type: "Point" , coordinates: [118.783799, 31.979234] } , spherical: true, limit:1, })
- find
db.order.find({"order_info.survey_coordinate" : { "$near" : { "$geometry" : { "type" : "Point", "coordinates" : [118.783799, 31.979234] } } } })
参考:
https://blog.csdn.net/u014230597/article/details/52635190
https://blog.csdn.net/medea_yang/article/details/53436460
流水:首次eBay海淘--GERBER 31-001901
作者:matrix 发布时间:2018-11-25 分类:零零星星
GERBER是贝尔代言的求生刀品牌 这刀JD报价2K死贵 https://item.jd.com/1546446.html
虽然没找到荒野求生同款 但是贝爷家的东西二话不说 收藏都值
去eBay看了下CNY 405.69,简直感动,但是运费的话按照最快的时间就要CNY202.97 价格比起狗东的要好很多。
刚刚正好从邱总(http://veryatom.com/)那里&小飞&倒唐一起聚了回来取了包裹。周一到今天周末EMS收货正好一个星期 很满意 没有多余费用。之前毕竟没有海淘的经验,只晓得运费贵 时间长 问题多。
eBay上购买的时候要看好商品是否支持邮寄中国,成色,运费这些 收货地址填写 价格合适就拍了。
大致过程参考:https://post.smzdm.com/p/54928/
刚开始怕老外不能打印中文的收货地址就填写的拼音,还好付款之后人家直接发邮件来说明可以打印中文地址信息 这样方便国内揽件。
Tracking number就是运单号 完成之后就是每天刷包裹信息,这把刀是从澳洲店铺买的 澳大利亚邮政包裹查询:https://auspost.com.au/mypost/track/#/search
国际邮政列表:http://www.ems.com.cn/mailtracking/cha_xun_lian_jie.html
到国内后的EMS包裹查询:
http://yjcx.chinapost.com.cn/qps/yjcx
http://intmail.183.com.cn/qps/yjcx
或者使用17track更方便:
https://www.17track.net/zh-cn
开箱图
国外测评YouTube:
贝爷是大学时候看荒野求生了解的,简直偶像。现在上班都是一屁股坐一天 很少时间走动,体能也差 但是心里很想出去玩玩 向往之~
PEACE