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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/usr/bin/env python
import googlemaps as gm
import sys, os
basedir = "gmfetch_DL"
dryrun = 1
for arg in sys.argv[1:]:
exec arg
if lon[0] > lon[1]:
lon = (lon[1], lon[0])
if lat[0] > lat[1]:
lat = (lat[1], lat[0])
print lon, lat
zooms = range(-5, 18)
zooms.reverse()
for z in zooms:
for d in ['sat', 'map', 'overlay', 'relief']:
try:
os.makedirs("%s/%s" % (basedir, d))
except:
pass
img_num = (gm.get_image_number(lon[0], lat[0], z), gm.get_image_number(lon[1], lat[1], z))
for y in range(img_num[1][1], img_num[0][1]+1):
for x in range(img_num[0][0], img_num[1][0]+1):
sel = gm.image_number_to_sel(x, y, z, ['a', 'b', 'c', 'd'])
if not dryrun:
img_sat = None
img_map = None
img_overlay = None
img_relief = None
img_sat_file = "%s/sat/%s" % ( basedir, sel)
img_map_file = "%s/map/%s" % ( basedir, sel)
img_overlay_file = "%s/overlay/%s" % ( basedir, sel)
img_relief_file = "%s/relief/%s" % ( basedir, sel)
if z >= gm.MIN_SATELLITE_ZOOM:
try:
pass
#os.stat(img_sat_file)
except OSError:
print "sat %d %d %d" % (x,y,z),
img_sat = gm.fetch_satellite_img(x, y, z)
if img_sat:
f = open("%s/sat/%s" % (basedir, sel), 'w')
f.write(img_sat)
f.close()
else:
print " failed",
print
if z >= gm.MIN_MAP_ZOOM:
try:
os.stat(img_map_file)
except OSError:
print "map %d %d %d" % (x,y,z),
img_map = gm.fetch_map_img(x, y, z)
if img_map:
f = open("%s/map/%s" % (basedir, sel), 'w')
f.write(img_map)
f.close()
else:
print " failed",
print
if z >= gm.MIN_OVERLAY_ZOOM:
try:
os.stat(img_overlay_file)
except OSError:
print "overlay %d %d %d" % (x,y,z),
img_overlay = gm.fetch_overlay_img(x, y, z)
if img_overlay:
f = open("%s/overlay/%s" % (basedir, sel), 'w')
f.write(img_overlay)
f.close()
else:
print " failed",
print
if z >= gm.MIN_RELIEF_ZOOM:
try:
os.stat(img_relief_file)
except:
print "relief %d %d %d" % (x,y,z),
img_relief = gm.fetch_relief_img(x, y, z)
if img_relief:
f = open("%s/relief/%s" % (basedir, sel), 'w')
f.write(img_relief)
f.close()
else:
print " failed",
print
|