1 Star 0 Fork 0

张一夫/BaiduMap_tiles

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
merge_tiles.py 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
kyer 提交于 2018-02-28 14:45 . feat: upgrade python2 to python3
from PIL import Image
import sys, os
from gmap_utils import *
def merge_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite=True):
TYPE, ext = 'r', 'png'
if satellite:
TYPE, ext = 's', 'jpg'
x_start, y_start = bd_latlng2xy(zoom, lat_start, lon_start)
x_stop, y_stop = bd_latlng2xy(zoom, lat_stop, lon_stop)
x_start = int(x_start/256)
y_start = int(y_start/256)
x_stop = int(x_stop/256)
y_stop = int(y_stop/256)
print("x range", x_start, x_stop)
print("y range", y_start, y_stop)
w = (x_stop - x_start) * 256
h = (y_stop - y_start) * 256
print("width:", w)
print("height:", h)
result = Image.new("RGBA", (w, h))
for x in range(x_start, x_stop):
for y in range(y_start, y_stop):
filename = "%d_%d_%d_%s.%s" % (zoom, x, y, TYPE, ext)
if not os.path.exists(filename):
print("-- missing", filename)
continue
x_paste = (x - x_start) * 256
y_paste = (y_stop - y) * 256
try:
i = Image.open(filename)
except Exception as e:
print("-- %s, removing %s" % (e, filename))
trash_dst = os.path.expanduser("~/.Trash/%s" % filename)
os.rename(filename, trash_dst)
continue
result.paste(i, (x_paste, y_paste))
del i
result.save("map_%s.%s" % (TYPE, ext))
if __name__ == "__main__":
zoom = 19
lat_start, lon_start = 31.022547,121.429391
lat_stop, lon_stop = 31.041453,121.45749
merge_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite=False)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Dontes_cn/BaiduMap_tiles.git
git@gitee.com:Dontes_cn/BaiduMap_tiles.git
Dontes_cn
BaiduMap_tiles
BaiduMap_tiles
master

搜索帮助