地图地址说明
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()