def make_animation(self, globals): icon_style = kml.IconStyle(globals.stock.animation_icon, color=self.color, scale=globals.stock.icon_scales[0]) list_style = kml.ListStyle(listItemType='checkHideChildren') style = kml.Style(icon_style, list_style) folder = kml.Folder(style, name='Animation', visibility=0) point = kml.Point(coordinates=[self.track.coords[0]], altitudeMode=self.altitude_mode) timespan = kml.TimeSpan(end=kml.dateTime(self.track.coords[0].dt)) placemark = kml.Placemark(point, timespan, styleUrl=style.url()) folder.add(placemark) for i in xrange(1, len(self.track.coords)): coord = self.track.coords[i - 1].halfway_to(self.track.coords[i]) point = kml.Point(coordinates=[coord], altitudeMode=self.altitude_mode) begin = kml.dateTime(self.track.coords[i - 1].dt) end = kml.dateTime(self.track.coords[i].dt) timespan = kml.TimeSpan(begin=begin, end=end) placemark = kml.Placemark(point, timespan, styleUrl=style.url()) folder.add(placemark) point = kml.Point(coordinates=[self.track.coords[-1]], altitudeMode=self.altitude_mode) timespan = kml.TimeSpan(begin=kml.dateTime(self.track.coords[-1].dt)) placemark = kml.Placemark(point, timespan, styleUrl=style.url()) folder.add(placemark) return kmz.kmz(folder)
def flights2kmz(flights, roots=[], tz_offset=0, task=None): stock = Stock() globals = util.OpenStruct() globals.stock = stock globals.bounds = util.BoundsSet() for flight in flights: globals.bounds.update(flight.track.bounds) if globals.bounds.climb.min < -5.0: globals.bounds.climb.min = -5.0 if globals.bounds.climb.max > 5.0: globals.bounds.climb.max = 5.0 globals.tz_offset = datetime.timedelta(0, 3600 * tz_offset) globals.task = task globals.scales = util.OpenStruct() globals.scales.altitude = Scale(globals.bounds.ele.tuple(), title='altitude', gradient=default_gradient) globals.altitude_styles = [] for i in xrange(0, 3): altitude_styles = [] for c in globals.scales.altitude.colors(): balloon_style = kml.BalloonStyle(text='$[description]') icon_style = kml.IconStyle(globals.stock.icons[i], color=c, scale=globals.stock.icon_scales[i]) label_style = kml.LabelStyle(color=c, scale=globals.stock.label_scales[i]) style = kml.Style(balloon_style, icon_style, label_style) altitude_styles.append(style) stock.kmz.add_roots(*altitude_styles) globals.altitude_styles.append(altitude_styles) gradient = bilinear_gradient globals.scales.climb = ZeroCenteredScale(globals.bounds.climb.tuple(), title='climb', step=0.1, gradient=gradient) globals.scales.speed = Scale(globals.bounds.speed.tuple(), title='ground speed', gradient=default_gradient) globals.scales.time = TimeScale(globals.bounds.time.tuple(), tz_offset=globals.tz_offset) globals.scales.t = Scale(globals.bounds.t.tuple(), title='time', gradient=default_gradient) if hasattr(globals.bounds, 'tas'): globals.scales.tas = Scale(globals.bounds.tas.tuple(), 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) if globals.task: result.add_siblings(make_task_folder(globals, globals.task)) for flight in flights: result.add_siblings(flight.to_kmz(globals)) return result
def make_analysis_style(self, color, bgcolors, rows): text = '<h3>$[name]</h3>$[description]' + make_table(rows, bgcolors) bg_color = 'ff' + ''.join(reversed(re.findall(r'..', bgcolors[1][1:]))) balloon_style = kml.BalloonStyle(text=kml.CDATA(text), bgColor=bg_color) icon_style = kml.IconStyle(self.icons[0], color=color, scale=self.icon_scales[0]) label_style = kml.LabelStyle(color=color, scale=self.label_scales[0]) line_style = kml.LineStyle(color=color, width=4) return kml.Style(balloon_style, icon_style, label_style, line_style)
def __init__(self): self.kmz = kmz.kmz() # self.icon_scales = [sqrt(x) for x in [0.6, 0.5, 0.4, 0.3]] self.icons = [kml.Icon.palette(4, i) for i in [25, 25, 24, 24]] self.label_scales = [sqrt(x) for x in [0.6, 0.5, 0.4, 0.3]] # list_style = kml.ListStyle(listItemType='radioFolder') self.radio_folder_style = kml.Style(list_style) self.kmz.add_roots(self.radio_folder_style) # list_style = kml.ListStyle(listItemType='checkHideChildren') self.check_hide_children_style = kml.Style(list_style) self.kmz.add_roots(self.check_hide_children_style) # bgcolors = '#ffcccc #ffdddd'.split() rows = [ ['Altitude gain', '$[altitude_change]m'], ['Average climb', '$[average_climb]m/s'], ['Maximum climb', '$[maximum_climb]m/s'], ['Peak climb', '$[peak_climb]m/s'], ['Efficiency', '$[efficiency]%'], ['Start altitude', '$[start_altitude]m'], ['Finish altitude', '$[finish_altitude]m'], ['Start time', '$[start_time]'], ['Finish time', '$[finish_time]'], ['Duration', '$[duration]'], ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'], ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'], ['Drift', '$[average_speed]km/h $[drift_direction]'], ] self.thermal_style = self.make_analysis_style('cc3333ff', bgcolors, rows) self.kmz.add_roots(self.thermal_style) bgcolors = '#ccccff #ddddff'.split() rows = [ ['Altitude change', '$[altitude_change]m'], ['Average descent', '$[average_climb]m/s'], ['Maximum descent', '$[maximum_descent]m/s'], ['Peak descent', '$[peak_descent]m/s'], ['Start altitude', '$[start_altitude]m'], ['Finish altitude', '$[finish_altitude]m'], ['Start time', '$[start_time]'], ['Finish time', '$[finish_time]'], ['Duration', '$[duration]'], ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'], ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'], ] self.dive_style = self.make_analysis_style('ccff3333', bgcolors, rows) bgcolors = '#ccffcc #ddffdd'.split() rows = [ ['Altitude change', '$[altitude_change]m'], ['Average descent', '$[average_climb]m/s'], ['Distance', '$[distance]km'], ['Average glide ratio', '$[average_ld]:1'], ['Average speed', '$[average_speed]km/h'], ['Start altitude', '$[start_altitude]m'], ['Finish altitude', '$[finish_altitude]m'], ['Start time', '$[start_time]'], ['Finish time', '$[finish_time]'], ['Duration', '$[duration]'], ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'], ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'], ] self.kmz.add_roots(self.dive_style) self.glide_style = self.make_analysis_style('cc33ff33', bgcolors, rows) self.kmz.add_roots(self.glide_style) # self.time_mark_styles = [] for i in xrange(0, len(self.icons)): icon_style = kml.IconStyle(self.icons[i], scale=self.icon_scales[i]) label_style = kml.LabelStyle(color='cc33ffff', scale=self.label_scales[i]) self.time_mark_styles.append(kml.Style(icon_style, label_style)) self.kmz.add_roots(*self.time_mark_styles) # balloon_style = kml.BalloonStyle(text=kml.CDATA('$[description]')) icon_style = kml.IconStyle(kml.Icon.palette(4, 46), scale=self.icon_scales[0]) label_style = kml.LabelStyle(scale=self.label_scales[0]) self.photo_style = kml.Style(balloon_style, icon_style, label_style) self.kmz.add_roots(self.photo_style) # text = kml.text(kml.CDATA('<h3>$[name]</h3>$[description]')) balloon_style = kml.BalloonStyle(text) icon_style = kml.IconStyle(self.icons[0], color='ccff33ff', scale=self.icon_scales[0]) label_style = kml.LabelStyle(color='ccff33ff', scale=self.label_scales[0]) line_style = kml.LineStyle(color='ccff33ff', width=2) self.xc_style = kml.Style(balloon_style, icon_style, label_style, line_style) self.kmz.add_roots(self.xc_style) # text = kml.text(kml.CDATA('<h3>$[name]</h3>$[description]')) balloon_style = kml.BalloonStyle(text) icon_style = kml.IconStyle(self.icons[0], color='ccff33ff', scale=self.icon_scales[0]) label_style = kml.LabelStyle(color='ccff33ff', scale=self.label_scales[0]) line_style = kml.LineStyle(color='ccff33ff') self.xc_style2 = kml.Style(balloon_style, icon_style, label_style, line_style) self.kmz.add_roots(self.xc_style2) # self.pixel_url = os.path.join('images', 'pixel.png') pixel = open(os.path.join(BASE_DIR, self.pixel_url)).read() self.kmz.add_files({self.pixel_url: pixel}) # self.visible_none_folder = self.make_none_folder(1) self.invisible_none_folder = self.make_none_folder(0) # animation_icon_url = os.path.join('images', 'paraglider.png') self.animation_icon = kml.Icon(href=animation_icon_url) animation_icon = open(os.path.join(BASE_DIR, animation_icon_url)).read() files = {animation_icon_url: animation_icon} self.kmz.add_files(files)