| 
 
	积分22790贡献 精华在线时间 小时注册时间2015-12-7最后登录1970-1-1 
 | 
 
| 
本帖最后由 葫芦爷儿 于 2019-10-22 14:26 编辑
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  
 现在已经找到了解决办法,将求助帖改为经验总结在python调用这类地图作为底图,核心思路是:下载瓦片地图,拼接,当图片加载到figure中。
 
 具体实现思路是:主要为两部分 1地图的使用 ;2python的使用
 在1 地图的使用中分为: 1.1 利用说明、google浏览器开发者工具找到不同底图的瓦片调用方式 ;1.2 根据调用方式,申请api接口的key
 在2 python的使用中分为:2.1 查找获取方式; 2.2 拼接方法; 2.3加载;但是发现cartopy已经有该功能,最简单的方式是在cartopy的基础上调整。
 
 现在介绍1:
 通过开发者工具发现了几类地图的调用, 具体看网址
 天地图:
 key:需要通过天地图官网申请 http://www.tianditu.gov.cn ,具体看网址
 
 OSM: https://www.openstreetmap.org/#map=6/29.591/122.198复制代码        url = 'http://t1.tianditu.gov.cn/DataServer?T=vec_w&x=%s&y=%s&l=%s&tk=%s' % (x, y, z, key)
 Google:需要换成国内的复制代码        url = 'https://a.tile.openstreetmap.org/%s/%s/%s.png' % (z, x, y)
 海鸥地图:https://cn.gullmap.com复制代码        url = 'http://mt2.google.cn/vt/lyrs=m@167000000&hl=zh-CN&gl=cn&x=%s&y=%s&z=%s'% (x, y, z)
 复制代码        url = 'https://cn.gullmap.com/rt/%s/%s/%s.png'% (z,x, y, )
现在介绍2:
 在cartopy中增加函数调用,1找到修改哪里 2参考OSM()进行修改,建议在pycharm或git上先看该函数;3若在linxu里, conda env list 查看环境的路径即可
 2019 1022修改:可以知道在 ../env/casename/lib/python3.6/site-packages/cartopy/io/img_tiles.py
 '2019 1022修改前:可以知道在/lib/cartopy/io/img_tiles.py脚本中‘
 可以在终端中,用
 现在找到img_tiles.py,增加天地图的函数TDT
 
 复制代码class TDT(GoogleWTS):
    def _image_url(self, tile):
          x, y, z = tile
          key = '自己申请'
          # 文字 url = 'http://t1.tianditu.gov.cn/DataServer?T=cva_w&x=%s&y=%s&l=%s&tk=%s' % (x, y, z, key)
          url = 'http://t1.tianditu.gov.cn/DataServer?T=vec_w&x=%s&y=%s&l=%s&tk=%s' % (x, y, z, key)
        return url
类似的:
 现在就可以调用了,参考 https://ocefpaf.github.io/python4oceanographers/blog/2015/06/22/osm/参考网:https://github.com/SciTools/cartopy/blob/e2bbaa85b17e1c76cb6cc75c352a84dd387fc17b/lib/cartopy/io/img_tiles.py复制代码class GoogleCN(GoogleWTS):
     def _image_url(self, tile):
          x, y, z = tile
          url = 'http://mt2.google.cn/vt/lyrs=m@167000000&hl=zh-CN&gl=cn&x=%s&y=%s&z=%s'% (x, y, z)
        return url
各种地图的汇总参考:https://github.com/yaosailor/raster-collection 因为较早,有些有一定的调整。
 
 
   
 
 
 -------------2019 0223 以下是之前的求助----------
 求助:因为作图需要行政区域作为底图,如何利用python调用天地图或百度地图,绘制底图。
 我尝试了cartopy,他利用开源地图的方式核心如下代码。但是有时候下载速度太慢,导致不能满足需要。
 参考:https://github.com/SciTools/cart ... opy/io/img_tiles.py复制代码class OSM(GoogleWTS):
    # http://developer.mapquest.com/web/products/open/map for terms of use
    def _image_url(self, tile):
        x, y, z = tile
        url = 'https://a.tile.openstreetmap.org/%s/%s/%s.png' % (z, x, y)
        return url
 
 
 下面是为了找画高精度地图参考的网址:
 1 下载数据网址  https://www.naturalearthdata.com/downloads/10m-raster-data/10m-cross-blend-hypso/
 2 如何调用Google osm shp绘制高精度地图,参考 https://ocefpaf.github.io/python4oceanographers/blog/2015/06/22/osm/
 3  如何更换底图 参考: http://www.thomasguymer.co.uk/blog/2018/2018-01-15/
 下载数据,将tif转换为png,写一个json说明文件
 
 cartopy默认地图的地址
 ~/.local/share/cartopy/shapefiles/natural_earth/physical
 
 
 
 
 | 
 评分
查看全部评分
 |