osm: add script to grab all tiles for an area
This commit is contained in:
parent
e8d4e1ba28
commit
3d6b62eac0
|
@ -0,0 +1,38 @@
|
|||
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, 19):
|
||||
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)
|
Loading…
Reference in New Issue