注册 登录
  • 注册时,本站名称为:RGB空格3S博客,注意中间的空格。
  • 2018.8.14本站全面接入google广告
  • 2017.2.14今天收到45条恶意评论(全是外文),故评论时请填写必要信息,匿名评论全部拉黑,迫不得已而为之
  • 2017.1.27,2017年春节及至,我谨代表本人祝大家新春快乐,本人年终总结文章请访问:2016年终总结
  • 为防止恶意转载,本站全面禁止复制,并添加图片水印:RGB 3S博客www.ixxin.cn。
  • 本站正式更名为RGB 3S博客,本站将撤消所有非3S内容,其将转移到新博客江湖时代

Python地理编码合集模块

Python admin 6254次浏览 已收录 3个评论
[隐藏]

前言

一个很有意思的模块”geocoder“,只要功能是地理编码与反地理编码,集合了国内外很多地图。

支持的地图:

support

演示

本次演示,IDE为ipython,api为Arcgis,因为他不需要Key。

地理编码

In [1]: import <a href="https://www.ixxin.cn/tag/geocoder/" title="查看更多关于geocoder的文章" target="_blank">geocoder</a>

In [2]: g = geocoder.arcgis("qingdao")

In [3]: g.wkt
Out[3]: 'POINT(120.371939388 36.098605988)'

In [4]: g.json
Out[4]:
{'address': u'Qingdao, Shandong, China',
 'bbox': {'northeast': [36.209606, 120.482939],
  'southwest': [35.987606, 120.260939]},
 'confidence': 1,
 'encoding': 'utf-8',
 'lat': 36.098605988000486,
 'lng': 120.37193938800056,
 'location': 'qingdao',
 'ok': True,
 'provider': 'arcgis',
 'quality': u'POI',
 'score': 100,
 'status': 'OK',
 'status_code': 200}

反地理编码

In [14]:  g = geocoder.arcgis([45.15,-75.14],method = "reverse")

In [15]: g.city
Out[15]: u'North Stormont'

In [16]: g.country
Out[16]: u'CAN'

IP地址

In [17]: g = geocoder.ip('199.7.157.0')

In [18]: g.city
Out[18]: u'Scarborough'

In [19]: g = geocoder.ip('me')

In [20]: g.city
Out[20]: u'Jinan

距离量算

In [26]: d = distance("Ottawa, ON", "Toronto, ON")

In [27]: print d
352.669845047

In [28]: d = distance("Ottawa, ON", "Toronto, ON",provider = "google")

In [29]: print d
352.669845047

In [30]: d = distance("Ottawa, ON", "Toronto, ON",provider = "arcgis")

In [31]: print d
352.669845047

In [32]:  d = distance("Ottawa, ON", "Toronto, ON",provider = "arcgis",units = "miles")

In [33]: print d
219.138814287


值得注意的是,默认地图为必应,默认单位不是米,中国的城市不能量测,如下:
In [25]: dis = distance("qingdao,ON","jinan,ON",provider = "google")
[WARNING] Error calculating the following two locations.
Points: qingdao,ON to jinan,ON

后语

作者GitHub地址:https://github.com/DenisCarriere/geocoder,可以去给他点星星。


xxin blog , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Python地理编码合集模块
喜欢 (2)
支付宝[853060844@qq.com]
分享 (0)
admin
关于作者:
坐标山科大遥感系小鲜肉一枚。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(3)个小伙伴在吐槽
  1. 这个玩意用处很大啊
    匿名2017-11-15 21:47 回复 Windows 10 | Chrome 55.0.2883.87
  2. 这个玩意用处蛮大的
    匿名2017-11-15 21:49 回复 Windows 10 | Chrome 55.0.2883.87
  3. 这个玩意似乎用处很大啊
    匿名2017-11-15 21:51 回复 Windows 10 | Chrome 55.0.2883.87