Browse Source

Merge branch 'master' of git://github.com/twpayne/igc2kmz

cfd
dkm 13 years ago
parent
commit
bf3f59db54
  1. 7
      bin/igc2task.py
  2. 24
      igc2kmz/__init__.py
  3. 14
      igc2kmz/etree.py
  4. 5
      igc2kmz/gpx.py

7
bin/igc2task.py

@ -32,7 +32,7 @@ except ImportError:
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from igc2kmz.coord import Coord
from igc2kmz.etree import tag
from igc2kmz.etree import pretty_write, tag
from igc2kmz.gpx import gpx_tag
from igc2kmz.igc import IGC
from igc2kmz.task import Task, Turnpoint
@ -151,8 +151,9 @@ def main(argv):
with gpx_tag(TreeBuilder()) as tb:
element = task.build_tree(tb).close()
output = open(options.output, 'w') if options.output else sys.stdout
output.write('<?xml version="1.0" encoding="utf-8"?>')
ElementTree(element).write(output)
output.write('<?xml version="1.0" encoding="utf-8"?>\n')
pretty_write(output, element)
if __name__ == '__main__':
main(sys.argv)

24
igc2kmz/__init__.py

@ -328,29 +328,37 @@ class Flight(object):
folder = kmz.kmz(kml.Folder(name='Track', open=1, styleUrl=style_url))
folder.add(globals.stock.invisible_none_folder)
if self.track.elevation_data:
visibility = globals.default_track == 'climb'
folder.add(self.make_colored_track(globals, self.track.climb,
globals.scales.climb,
'absolute'))
'absolute',
visibility=visibility))
visibility = globals.default_track == 'altitude'
folder.add(self.make_colored_track(globals, self.track.ele,
globals.scales.altitude,
'absolute', visibility=0))
visibility = not self.track.elevation_data
'absolute',
visibility=visibility))
visibility = globals.default_track == 'speed'
folder.add(self.make_colored_track(globals, self.track.speed,
globals.scales.speed,
self.altitude_mode,
visibility=visibility))
if hasattr(self.track, 'tas'):
visibility = globals.default_track == 'tas'
folder.add(self.make_colored_track(globals, self.track.tas,
globals.scales.tas,
self.altitude_mode,
visibility=0))
visibility=visibility))
visibility = globals.default_track == 'time'
folder.add(self.make_colored_track(globals, self.track.t,
globals.scales.t, self.altitude_mode,
scale_chart=False,
visibility=visibility))
visibility = globals.default_track == 'solid_color'
style = kml.Style(kml.LineStyle(color=self.color, width=self.width))
folder.add(self.make_solid_track(globals, style, self.altitude_mode,
name='Solid color', visibility=0))
name='Solid color',
visibility=visibility))
return folder
def make_shadow_folder(self, globals):
@ -852,6 +860,12 @@ def flights2kmz(flights, roots=[], tz_offset=0, task=None):
title='air speed', gradient=default_gradient)
globals.graph_width = 600
globals.graph_height = 300
globals.default_track = 'solid_color'
if len(flights) == 1:
if flights[0].track.elevation_data:
globals.default_track = 'climb'
else:
globals.default_track = 'speed'
result = kmz.kmz()
result.add_siblings(stock.kmz)
result.add_roots(kml.open(1), *roots)

14
igc2kmz/etree.py

@ -28,3 +28,17 @@ class tag(object):
def __exit__(self, type, value, traceback):
self.tb.end(self.name)
def pretty_write(io, element, indent='\t', prefix=''):
attrs = ''.join(' %s="%s"' % item for item in element.items())
children = element.getchildren()
if children:
io.write('%s<%s%s>\n' % (prefix, element.tag, attrs))
for child in children:
pretty_write(io, child, indent, prefix + indent)
io.write('%s</%s>\n' % (prefix, element.tag))
elif element.text:
io.write('%s<%s%s>%s</%s>\n' % (prefix, element.tag, attrs, element.text, element.tag))
else:
io.write('%s<%s%s/>\n' % (prefix, element.tag, attrs))

5
igc2kmz/gpx.py

@ -16,6 +16,7 @@
from datetime import datetime
import math
import re
try:
from xml.etree.cElementTree import parse
@ -63,8 +64,8 @@ class GPX(object):
self.coords = []
for trkpt in element.findall('/{%s}trk/{%s}trkseg/{%s}trkpt'
% (namespace, namespace, namespace)):
lat = float(trkpt.get('lat'))
lon = float(trkpt.get('lon'))
lat = math.pi * float(trkpt.get('lat')) / 180.0
lon = math.pi * float(trkpt.get('lon')) / 180.0
ele_tag = trkpt.find(ele_tag_name)
ele = 0 if ele_tag is None else float(ele_tag.text)
time = trkpt.find(time_tag_name)

Loading…
Cancel
Save