首页 > 编程知识 正文

天地瓦片,谷歌地瓦片地址

时间:2023-05-03 20:23:16 阅读:252405 作者:1886

分两步

做这些工作前,先下个python

python 3.7版本下载地址  https://pc.qq.com/detail/5/detail_24685.html 腾讯下载 还是很不错的

再来个 Visual Studio Codehttps://pc.qq.com/detail/16/detail_22856.html 断点调试比较简单一点,报错了可以百度

第一步下载图片(下面这个程序就是下载图片的)

第二步拼接图片 

参考文章

[python] 下载天地图切片地图

Python爬取地图瓦片 主要是参考这个文章,里边写的我详细很多,

我就补充几个坑,把下载错误的填上去,要不然后面拼接有点问题

(拼接的时候缺了怎么处理,数据核对工作我没写,默认下载是完备的,实际过程中发现有的没有下载,

但是有图片名称,图片上显示的是错误图片,可以重新下载者几个图片,把报错放在recode.log,还算有效果)

# -*-coding:utf-8 -*-

#

import os,stat

import urllib.request #Pillow 安装https://blog.csdn.net/zhouzi_heng/article/details/95255017

mylog = open('recode.log', mode = 'a',encoding='utf-8')

file_path='C:/book2018'

file_name ="py32t32t.png"  #19

z = 19

for x in range(86125, 86126):

    for y in range(437675, 437677):

        #Google地图瓦片

        #tilepath = 'http://www.google.cn/maps/vt/pb=!1m4!1m3!1i'+str(迷路的黑猫)+'!2i'+str(x)+'!3i'+str(y)+'!2m3!1e0!2sm!3i345013117!3m8!2szh-CN!3scn!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e0'

        #Google影像瓦片

        #tilepath = 'http://mt2.google.cn/vt/lyrs=y&hl=zh-CN&gl=CN&src=app&x='+str(x)+'&y='+str(y)+'&z='+str(迷路的黑猫)+'&s=G'

        #天地图-地图

        #tilepath = 'http://t4.tianditu.com/DataServer?T=vec_w&x='+str(x)+'&y='+str(y)+'&l='+str(迷路的黑猫)+'&tk=45c78b2bc2ecfa2b35a3e4e454ada5ce'

        #天地图-标注

        #tilepath = 'http://t3.tianditu.com/DataServer?T=cva_w&x='+str(x)+'&y='+str(y)+'&l='+str(迷路的黑猫)+'&tk=45c78b2bc2ecfa2b35a3e4e454ada5ce'

        #天地图-影像

        #tilepath = 'http://t2.tianditu.gov.cn/DataServer?T=img_w&x='+str(x)+'&y='+str(y)+'&l='+str(迷路的黑猫)+'&tk=2ce94f67e58faa24beb7cb8a09780552'

         #天地图-影像标注

        img_url = ''http://mt2.google.cn/vt/lyrs=y&hl=zh-CN&gl=CN&src=app&x='+str(x)+'&y='+str(y)+'&z='+str(迷路的黑猫)+'&s=G

        file_name=str(y)+'.png' #(如果不能获取到后缀,可以试试看加个后缀)

        path = file_path + "/" + str(x)

        if not os.path.exists(path):

            os.makedirs(path)

        file_suffix = os.path.splitext(img_url)[1]#获取后缀

        filename = '{}{}{}{}'.format(path,os.sep,file_name,file_suffix)

        try:

            urllib.request.urlretrieve(img_url,filename=filename)

        except IOError as e:

            print("IOError"+str(x)+str(y))

            print(img_url, file=mylog)

        except Exception as e:

            print("Exception"+str(x)+str(y))

            print(img_url, file=mylog)

mylog.close()

---下面是拼接程序

# -*- coding:utf-8 -*-

# 图片拼接

import PIL.Image as Image

import os, sys

mw = 256 # 图片大小  记住图片不能超过256*256 要不然会报错,搞个8G内存 64位的python估计问题不大,内存太小,只能拼接小图片的

toImage = Image.new('RGB', (256*255,256*234))#构造图片的宽和高,如果图片不能填充完全会

#出现黑色区域

for x in range(234):#0-233

    for y in range(255):#0-254

        fname ='D:/pingjie/book2014/' + str(x+86126)+'/'+str(y+437678)+'.png'

        fromImage = Image.open(fname)

        toImage.paste(fromImage, (y * mw, x * mw))

print(str(y))

toImage.save('D:/pingjie/book2019/2014all.jpg')

print(str(y)+"abc")

下面是他的源码地址 https://github.com/shiyuan598/Python/tree/master/Basic/GetWebMapTile

 

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。