39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import math
|
|
import os
|
|
import requests
|
|
|
|
def deg2num(lat_deg, lon_deg, zoom):
|
|
lat_rad = math.radians(lat_deg)
|
|
n = 2.0 ** zoom
|
|
xtile = int((lon_deg + 180.0) / 360.0 * n)
|
|
ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
|
|
return (xtile, ytile)
|
|
|
|
|
|
COMBO_MAP_MAX_BOUNDS = {
|
|
"corner1": {"lat": 45.9134, "lng": 4.6733},
|
|
"corner2": {"lat": 45.5583, "lng": 5.1574}
|
|
}
|
|
|
|
for zoom in range(3, 20):
|
|
xtile1, ytile1 = deg2num(COMBO_MAP_MAX_BOUNDS['corner1']['lat'],
|
|
COMBO_MAP_MAX_BOUNDS['corner1']['lng'],
|
|
zoom)
|
|
xtile2, ytile2 = deg2num(COMBO_MAP_MAX_BOUNDS['corner2']['lat'],
|
|
COMBO_MAP_MAX_BOUNDS['corner2']['lng'],
|
|
zoom)
|
|
for xtile in range(xtile1, xtile2+1):
|
|
for ytile in range(ytile1, ytile2+1):
|
|
path = '%s/%s/%s.png' % (zoom, xtile, ytile)
|
|
if os.path.exists(path):
|
|
continue
|
|
url = 'https://tiles.entrouvert.org/hdm/%s/%s/%s.png' % (zoom, xtile, ytile)
|
|
print url
|
|
if not os.path.exists(os.path.dirname(path)):
|
|
os.makedirs(os.path.dirname(path))
|
|
r = requests.get(url)
|
|
if r.status_code != 200:
|
|
continue
|
|
with open(path, 'w') as fd:
|
|
fd.write(r.content)
|