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

Google地图瓦片爬虫

地图地址说明

1、谷歌矢量(中文标注)

http://mt{0-3}.google.cn/vt/v=m@416115521&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}&s=Galileo

2、谷歌矢量(英文标注)

http://mt{0-3}.google.cn/vt/v=m@416115521&hl=en&gl=cn&x={x}&y={y}&z={z}&s=Galileo

3、谷歌矢量(大字标注)

http://mt{0-3}.google.cn/vt/imgtp=png32&v=m@416115521&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}&s=Galileo&scale=2

4、谷歌影像

http://mt{0-3}.google.cn/maps/vt?lyrs=s&hl=zh-CN&gl=CN&x={x}&y={y}&z={z}

5、谷歌影像(中文标注)

http://mt{0-3}.google.cn/maps/vt?lyrs=y&hl=zh-CN&gl=CN&x={x}&y={y}&z={z}

6、谷歌影像(英文标注)

http://mt{0-3}.google.cn/maps/vt?lyrs=y&hl=zh-en&gl=CN&x={x}&y={y}&z={z}

7、谷歌地形(中文标注)

http://mt{0-3}.google.cn/maps/vt?lyrs=p&hl=zh-CN&gl=CN&x={x}&y={y}&z={z}

8、谷歌地形(英文标注)

http://mt{0-3}.google.cn/maps/vt?lyrs=p&hl=zh-en&gl=CN&x={x}&y={y}&z={z}

9、谷歌路网

http://mt{0-3}.google.cn/vt/lyrs=h@167000000&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}&s=Galil

10、谷歌影像(大字标注)

http://mt{0-3}.google.cn/vt/imgtp=png32&v=h@416115521&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}&s=Galile&scale=2

python程序

关键点说明:

  • 使用sqlite3存储瓦片,定义数据库结构
    CREATE TABLE {db_name} (tileX integer, tileY integer, tileZ integer, image blob,UNIQUE(tileZ, tileX, tileY));
    
  • 按照经纬度范围和级别计算瓦片列表:tile_list = list(mercantile.tiles(west, south, east, north, zoom_range, truncate=True))
import random
import sqlite3
import timeimport mercantile
import requestsextent = [-180, -90, 180, 90]
zoom_range = list(range(5, 12))db_name = "satellite"url_dict = {"satellite": "http://www.google.com/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}","road": "http://www.google.cn/maps/vt?lyrs=h@189&gl=cn&x={x}&y={y}&z={z}","street": "http://www.google.com/maps/vt?lyrs=p@189&gl=cn&x={x}&y={y}&z={z}"
}headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ""Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}proxies = {"http": "http://127.0.0.1:7890","https": "http://127.0.0.1:7890"
}db = fr"D:\数据\谷歌影像\{db_name}.db"west, south, east, north = extenttile_list = list(mercantile.tiles(west, south, east, north, zoom_range, truncate=True))
print(len(tile_list))
# 打乱顺序
random.shuffle(tile_list)con = sqlite3.connect(db)
cursor = con.cursor()cursor.execute(f"""SELECT name FROM sqlite_master WHERE type='table' AND name='{db_name}';""")
table_exists = cursor.fetchone()if not table_exists:cursor.execute(f"""CREATE TABLE {db_name} (tileX integer, tileY integer, tileZ integer, image blob,UNIQUE(tileZ, tileX, tileY));""")for tile in tile_list:url = url_dict[db_name].format(x=tile.x, y=tile.y, z=tile.z)print(url)cursor.execute(f"""SELECT 1 FROM {db_name} WHERE tileZ=? AND tileX=? AND tileY=?;""", (tile.z, tile.x, tile.y))if cursor.fetchone():print(f"Data for tile ({tile.z}, {tile.x}, {tile.y}) already exists. Skipping...")continuecount = 0content = b""while count < 10:r = requests.get(url, headers=headers, proxies=proxies)content = r.contentif content:breakcount += 1print(f"Retry tile {tile.z}, {tile.x}, {tile.y}")time.sleep(1)if not content:raise Exception(f"No data from {tile.z}, {tile.x}, {tile.y}")time.sleep(0.1)sql = f"INSERT INTO {db_name} (tileZ, tileX, tileY, image) VALUES (?, ?, ?, ?);"cursor.execute(sql, (tile.z, tile.x, tile.y, sqlite3.Binary(content)))con.commit()con.close()
http://www.lryc.cn/news/522126.html

相关文章:

  • 【C++】size_t全面解析与深入拓展
  • Web端实时播放RTSP视频流(监控)
  • 学习 Git 的工作原理,而不仅仅是命令
  • C语言变长嵌套数组常量初始化定义技巧
  • 如何查看特定版本的Spring源码
  • 【深度学习】关键技术-激活函数(Activation Functions)
  • 网关相关知识
  • SpringBoot整合SpringSecurity详解
  • 【C++基础】enum,union,uint8_t,static
  • 单片机的原理及其应用:从入门到进阶的全方位指南
  • 如何使用 Go语言操作亚马逊 S3 对象云存储
  • 2025年应用与API安全展望:挑战与机遇并存
  • Linux安装docker,安装配置xrdp远程桌面
  • VD:生成a2l文件
  • 【SpringBoot应用篇】SpringBoot+MDC+自定义Filter操作traceId实现日志链路追踪
  • unity2022以上导出到AndroidStudio后更新步骤
  • 【ArcGIS初学】产生随机点计算混淆矩阵
  • Harmony面试模版
  • PCM5142集成32位384kHz PCM音频立体声114dB差分输出DAC编解码芯片
  • 浪潮云财务系统xtdysrv.asmx存在命令执行漏洞
  • 【网络编程】基础知识
  • ResNet (Residual Network) - 残差网络:深度卷积神经网络的突破
  • MOSFET体二极管的反向恢复分析
  • 80_Redis内存策略
  • 【HarmonyOS NAPI 深度探索6】使用 N-API 创建第一个 Hello World 原生模块
  • Java语言的软件工程
  • 【Mysql进阶知识】Mysql 程序的介绍、选项在命令行配置文件的使用、选项在配置文件中的语法
  • wireshark抓路由器上的包 抓包路由器数据
  • 玩转大语言模型——使用graphRAG+Ollama构建知识图谱
  • python flask简单实践