1
2
3 __version__ = '$Revision: 2453 $'.split()[1]
4 __date__ = '$Date: 2006-10-27 14:54:22 -0400 (Fri, 27 Oct 2006) $'.split()[1]
5 __author__ = 'Kurt Schwehr'
6
7 __doc__='''
8 Convert xy label ascii files to kml lines
9
10
11 @author: U{'''+__author__+'''<http://schwehr.org/>} FIX: replace with your name/url
12 @version: ''' + __version__ +'''
13 @copyright: 2006
14 @var __date__: Date of last svn commit
15 @undocumented: __version__ __author__ __doc__ myparser
16 @since: 2006-Sep-26 FIX: replace with the file creation date
17 @status: under development
18 @organization: U{CCOM<http://ccom.unh.edu/>}
19
20 @license: CCOM internal use only, unless explicitly authorized
21
22 @seealso: U{Google's kml page<http://earth.google.com/kml/>}
23 @seealso: U{Google's kml 2.1 page<http://earth.google.com/kml/kml_tags_21.html>}
24 '''
25
26 import sys, time
27 from StringIO import StringIO
28
29
31 '''
32 Write out a time line placemark
33 @param outFile: file or StringIO object to write to
34 @param name: string to call the placemark
35 @param color: What color to make the line (e.g. ff00ff00)
36 @param id: some id string??? U{XML ID<http://www.w3.org/TR/xmlschema11-2/#ID>}. Need for updates (not yet handled?
37 @param points: list of triplets of ( decimalLon, decimalLat, timeSecUtc)
38 '''
39 o = outFile
40
41 return outFile
42
43
45 '''
46 param outfile: file like object
47 '''
48 o = outfile
49 o.write('<?xml version="1.0" encoding="UTF-8"?>\n')
50 o.write('<!-- Revition: '+__version__+' -->\n')
51 o.write('<!-- Software date: '+__date__+' -->\n')
52 o.write('<!-- Prototype Google Earth visualization by Kurt Schwehr -->\n')
53 o.write('<!-- We are using timeSpans which is only in 2.1 and newer -->\n')
54 o.write('<kml xmlns="http://earth.google.com/kml/2.1">\n')
55 o.write(' <Document>\n')
56 return o
57
59 outfile.write(' </Document>\n')
60 outfile.write('</kml>\n')
61 return outfile
62
63
64 def dumpPoints(self):
65 '''
66 Evaluate all added points into kml
67 '''
68
69
70
71
72
73
74
75
76
77 if __name__ == '__main__':
78 from optparse import OptionParser
79 myparser = OptionParser(usage="%prog [options]",
80 version="%prog "+__version__+' ('+__date__+')')
81
82 myparser.add_option('-o',dest='outfile',default='new.kml',
83 help='run the documentation tests [default: %default]')
84
85
86 myparser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true',
87 help='run the tests run in verbose mode')
88
89 myparser.add_option('-z',dest="zOffset",default=0,type=float,
90 help='Apply a zoffset to the line')
91
92 (options,args) = myparser.parse_args()
93
94
95
96
97
98
99 o = file(options.outfile,'w')
100 o = kmlHeader(o)
101
102 o.write('\t<Folder>\n')
103 o.write('\t\t<name>Some xy placemarks</name>\n')
104
105
106
107 for filename in args:
108
109
110 for line in file(filename):
111 indent='\t'
112 fields = line.split()
113 o.write(indent+'<Placemark><name>'+fields[2]+'</name><Point><coordinates>'+fields[0]+','+fields[1]+',0')
114 o.write('</coordinates></Point>')
115 o.write('</Placemark>\n')
116
117
118 o.write('\t</Folder>\n')
119 o = kmlTail(o)
120