-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_map.py
34 lines (31 loc) · 874 Bytes
/
get_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from urllib2 import urlopen
from pylab import imshow, imread, show
lon = [49.5,50.35]
lat = [18.6,20.2]
scale = 700000
print "Downloading map... "
tries = 0
url = None
while tries < 60:
tries += 1
print 'Try {}...'.format(tries)
try:
url = urlopen('http://parent.tile.openstreetmap.org/cgi-bin/export?'
'bbox={lat1:.2f},{lon1:.2f},{lat2:.2f},{lon2:.2f}&'
'scale={scale:d}&format=png'.format(lat1=lat[0],
lat2=lat[1],
lon1=lon[0],
lon2=lon[1],
scale=scale))
except HTTPError:
sleep(5)
continue
else:
print 'Map successfully downloaded.'
break
if url is None:
print 'Failed to download a map.'
else:
m = imread(url)
imshow(m, extent=lat+lon, aspect='equal')
show()