-
Notifications
You must be signed in to change notification settings - Fork 4
/
geo2png.py
executable file
·81 lines (72 loc) · 1.56 KB
/
geo2png.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
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
# trafo -> png
import png, gzip
settings = {
'icon' : {
'x' : 80,
'y' : 80,
'diffr' : 80,
'diffg' : 5,
'diffb' : 1
},
'tiny' : {
'x' : 500,
'y' : 250,
'diffr' : 100,
'diffg' : 10,
'diffb' : 2
},
'small' : {
'x' : 1000,
'y' : 500,
'diffr' : 100,
'diffg' : 25,
'diffb' : 8
},
'normal' : {
'x' : 2000,
'y' : 1000,
'diffr' : 150,
'diffg' : 40,
'diffb' : 10
},
'big' : {
'x' : 4000,
'y' : 2000,
'diffr' : 150,
'diffg' : 50,
'diffb' : 10
},
'huge' : {
'x' : 8000,
'y' : 4000,
'diffr' : 150,
'diffg' : 70,
'diffb' : 20
}
}
for size in settings.keys() :
print size
print settings[size]
p = [[0]*(settings[size]['x'] * 3) for i in range(settings[size]['y'])]
count = 0
with gzip.open('geo.txt.gz') as f :
for line in f :
if line.startswith('#') : continue
geoy, geox, property, subject = line.split()
if float(geox) > 180 or float(geox) < -180 or float(geoy) > 90 or float(geoy) < -90 :
print geoy, geox
continue
posx = int((float(geox) + 180.0)/361.0*settings[size]['x'])
posy = abs(int((float(geoy) - 90.0)/181.0*settings[size]['y']))
p[posy][posx*3] = min(p[posy][posx*3]+settings[size]['diffr'], 255)
p[posy][posx*3+1] = min(p[posy][posx*3+1]+settings[size]['diffg'], 255)
p[posy][posx*3+2] = min(p[posy][posx*3+2]+settings[size]['diffb'], 255)
count += 1
#if count > 10 : break
print size, "Map ready..."
print count, "entities"
f = open('map_' + size + '.png', 'wb')
w = png.Writer(settings[size]['x'], settings[size]['y'])
w.write(f, p)
f.close()
print "Finished."