-
Notifications
You must be signed in to change notification settings - Fork 0
/
Output.py
103 lines (92 loc) · 3.33 KB
/
Output.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Output module
import geopy
import codecs
import utility
import codecs
import logging
log = logging.getLogger('geocachepython.Output')
#icons borrowed from: http://www.thepropers.com/geocaching/60SeriesCustomSymbols.htm
def initKML(f):
f.write('<?xml version="1.0" encoding="UTF-8"?>\n' +
'<kml xmlns="http://www.opengis.net/kml/2.2">\n' +
'<Document>\n' +
' <Style id="Traditional">\n' +
' <IconStyle>\n' +
' <Icon>\n' +
' <href>http://alarobric.homeip.net/geocacheicons/000.bmp</href>\n' +
' </Icon>\n' +
' </IconStyle>\n' +
' </Style>\n' +
' <Style id="GreenTrans">\n' +
' <LineStyle>\n' +
' <width>2</width>\n' +
' </LineStyle>\n' +
' <PolyStyle>\n' +
' <color>7f00ff00</color>\n' +
' </PolyStyle>\n' +
' </Style>\n')
def closeKML(f):
f.write('</Document>\n' + '</kml>\n')
def createCircleKML(f, aLatLonCenter, radius, name='cache'):
latLonCenter = geopy.util.parse_geo(aLatLonCenter)
vertices = []
angle = 0.0
while angle <= 360:
vertex = geopy.distance.destination(latLonCenter, angle, radius)
vertices.append(vertex)
angle = angle + 10
firstVertex = vertices[0]
vertices.append(firstVertex)
f.write('<Placemark>\n' +
'<name>' + name + '</name>\n' +
'<styleUrl>#GreenTrans</styleUrl>\n' +
'<Polygon>\n' +
'<extrude>1</extrude>\n' +
'<altitudeMode>clampToGround</altitudeMode>\n' +
'<outerBoundaryIs>\n' +
'<LinearRing>\n' +
'<coordinates>')
for vertex in vertices:
f.write(str(vertex[1]) + ',' + str(vertex[0]) + ',' + '0\n')
f.write('</coordinates>\n' +
'</LinearRing>\n' +
'</outerBoundaryIs>\n' +
'</Polygon>\n' +
'</Placemark>\n' +
'<Placemark>\n' +
'<name>' + name + '</name>\n' +
'<description>' + name + '</description>\n' +
'<Point>\n' +
'<extrude>1</extrude>\n' +
'<altitudeMode>clampToGround</altitudeMode>\n' +
'<coordinates>\n' +
str(latLonCenter[1]) + ',' + str(latLonCenter[0]) + ',' + '0\n' +
'</coordinates>\n' +
'</Point>\n' +
'</Placemark>\n')
def writeKML(cacheList):
filename = utility.saveFileDialog('kml')
log.debug(filename)
f = codecs.open(filename, 'w', encoding="utf-8", errors="strict")
initKML(f)
for cache in cacheList:
createCircleKML(f, str(cache.lat) + ' ' + str(cache.lon), 0.161, cache.cacheName)
closeKML(f)
f.close()
def writeCSV(cacheList):
filename = utility.saveFileDialog('csv')
log.debug(filename)
f = codecs.open(filename, 'w', encoding="utf-8", errors="strict")
f.write('GCID,cacheName,Difficulty, Terrain\n')
for cache in cacheList:
try:
f.write("%s,%s,%s,%s\n" %(cache.gcid, cache.cacheName, cache.difficulty, cache.terrain))
except UnicodeDecodeError:
log.critical('Unicode error')
f.close()
# Check if running as a program
if __name__ == '__main__':
print "Run Debug Suite"
else:
# No, I must have been imported as a module
pass