1
2 __author__ = "Jon Goodall <jon.goodall@gmail.com> - http://www.duke.edu/~jgl34"
3 __version__ = "0.0.1"
4 __license__ = ""
5 __copyright__ =""
6
7 class KML_File:
8 "For creating KML files used for Google Earth"
9 def __init__(self, filepath):
10 self.filepath = filepath
11 "adds the kml header to a file (includes a default style)"
12 file = open(filepath,"w")
13 file.write(
14 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
15 "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"\
16 "<Document>\n"\
17 "<Style id='normalPlaceMarker'>\n"\
18 " <IconStyle>\n"\
19 " <Icon>\n"\
20 " <href>root://icons/palette-3.png</href>\n"\
21 " <x>96</x>\n"\
22 " <y>160</y>\n"\
23 " <w>32</w>\n"\
24 " <h>32</h>\n"\
25 " </Icon>\n"\
26 " </IconStyle>\n"\
27 "</Style>\n")
28 file.close()
29
30 def close(self):
31 file = open(self.filepath,"a")
32 file.write(
33 "</Document>\n"\
34 "</kml>")
35 file.close()
36
37 def open_folder(self, name):
38 file = open(self.filepath,"a")
39 file.write(
40 "<Folder>\n"\
41 " <name>" + name + "</name>\n")
42 file.close()
43
44 def close_folder(self):
45 file = open(self.filepath,"a")
46 file.write(
47 "</Folder>\n")
48 file.close()
49
50 def add_placemarker(self, latitude, longitude, altitude = 0.0, description = " ", name = " ", range = 6000, tilt = 45, heading = 0):
51 "adds the point to a kml file"
52 file = open(self.filepath,"a")
53 file.write(
54 "<Placemark>\n"\
55 " <description>" + description + "</description>\n"\
56 " <name>" + name + "</name>\n"\
57 " <styleUrl>#normalPlaceMarker</styleUrl>" +
58 " <LookAt>\n"\
59 " <longitude>" + str(longitude) + "</longitude>\n"\
60 " <latitude>" + str(latitude) + "</latitude>\n"\
61 " <range>" + str(range) + "</range>\n"\
62 " <tilt>" + str(tilt) + "</tilt>\n"\
63 " <heading>" + str(heading) + "</heading>\n"\
64 " </LookAt>\n"\
65 " <visibility>0</visibility>\n"\
66 " <Point>\n"\
67 " <extrude>1</extrude>\n"\
68 " <altitudeMode>relativeToGround</altitudeMode>\n"\
69 " <coordinates>" + str(longitude) + "," + str(latitude) +", " + str(altitude) + "</coordinates>\n"\
70 " </Point>\n"\
71 " </Placemark>\n")
72 file.close()