def create_tour_doc(tour_doc, row, imageInterval): camHeight = row['Z'] longitude, latitude = myProj(row['X'], row['Y'], inverse = True) azimuth = row['azimuth'] zenith = row['zenith'] intervalNo = row['intervalNo'] corrChunk = imageInterval[int(intervalNo)] # define a variable for the Google Extensions namespace URL string gxns = '{' + nsmap['gx'] + '}' #fly to the subChunk with the given subChunk parameters tour_doc.Document[gxns+"Tour"].Playlist.append( GX.FlyTo( GX.flyToMode("bounce"), KML.LookAt( KML.longitude(longitude),#change chunk[] to subChunk from csv KML.latitude(latitude),#change chunk[] to subChunk from csv KML.altitude(camHeight),#change chunk[] to subChunk from csv KML.heading(azimuth),#change chunk[] to subChunk from csv KML.tilt(zenith),#change chunk[] to subChunk from csv KML.range(corrChunk['range0']),#change all chunk[] to subChunk from csv KML.altitudeMode(corrChunk['altitudeMode']), GX.horizFov(horizFov) ) ) ) tour_doc.Document[gxns+"Tour"].Playlist.append(GX.Wait(GX.duration(corrChunk['lookAtDuration'])))
def getkml(self): avgalt = sum([i.Altitude for i in self.waypoints]) / float(len(self.waypoints)) minlat = min([i.Latitude for i in self.waypoints]) minlon = min([i.Longitude for i in self.waypoints]) maxlon = max([i.Longitude for i in self.waypoints]) maxlat = max([ i.Latitude + (i.Altitude - avgalt) / (60.0 * 1852.0 * math.cos(math.radians(-20))) for i in self.waypoints ]) if abs(maxlon - minlon) > abs(maxlat - minlat): rang = abs(maxlon - minlon) * 60.0 * 1852.0 / ( 2.0 * math.sin(math.radians(self.hfov) / 2.0)) * 1.2 else: rang = abs(maxlat - minlat) * 60.0 * 1852.0 / ( 2.0 * math.sin(math.radians(self.hfov) / 2.0)) * 16.0 / 9.0 txtwaypoints = ' '.join([ '%f,%f,%f' % (i.Longitude, i.Latitude, i.Altitude) for i in self.waypoints ]) txtsmoothed = ' '.join([ '%f,%f,%f' % (i.Longitude, i.Latitude, i.Altitude) for i in self.smoothed ]) wfolder = KML.Folder( KML.name('WayPoint Markers'), KML.visibility(1), ) pfolder = KML.Folder( KML.name('POI Markers'), KML.visibility(1), ) vfolder = KML.Folder( KML.name('WayPoint Views'), KML.visibility(0), ) playlist = GX.Playlist() #TODO: CDATA virtmission = KML.kml( KML.Document( KML.name(self.mission), KML.LookAt( KML.latitude((minlat + maxlat) / 2.0), KML.longitude((minlon + maxlon) / 2.0), KML.altitude(avgalt), KML.heading(0), KML.tilt(70), KML.range(rang), KML.altitudeMode("absolute"), GX.horizFov(self.hfov), ), GX.Tour( KML.name('Virtual Mission'), playlist, ), KML.Style( KML.LineStyle( KML.color('FF00FFFF'), KML.width(2), ), KML.PolyStyle(KML.color('4C00FFFF'), ), id='wpstyle', ), KML.Style( KML.LineStyle( KML.color('FFFF00FF'), KML.width(2), ), KML.PolyStyle(KML.color('4CFF00FF'), ), id='smoothstyle', ), KML.Style( KML.IconStyle( KML.Icon( KML.href( 'http://maps.google.com/mapfiles/kml/paddle/wht-blank.png' ), ), ), KML.BalloonStyle( KML.text( '\n<h3>WayPoint $[Waypoint]</h3>\n<table border="0" width="200">\n<tr><td>Altitude (msl) <td>$[Altitude_Abs] m\n<tr><td>Altitude (rtg) <td>$[Altitude_Gnd] m\n<tr><td>Heading<td>$[Heading] degrees\n<tr><td>Gimbal Tilt<td> $[Gimbal] degrees\n</tr></table>\n' ), KML.bgColor('ffffffbb'), ), id='wpmarkers', ), KML.Style( KML.IconStyle( KML.Icon( KML.href( 'http://maps.google.com/mapfiles/kml/paddle/red-stars.png' ), ), ), KML.BalloonStyle( KML.text( '\n<h3>POI $[POI]</h3>\n <table border="0" width="200">\n <tr><td>Altitude (msl) <td>$[Altitude_Abs] m\n <tr><td>Altitude (rtg) <td>$[Altitude_Gnd] m\n </tr></table>\n' ), KML.bgColor('ffffffbb'), ), id='poimarkers', ), KML.Folder( KML.name('Diagnostics'), KML.Placemark( KML.name('WayPoint Path'), KML.visibility(0), KML.styleUrl('#wpstyle'), KML.LineString( KML.extrude(1), KML.tessellate(1), KML.altitudeMode('absolute'), KML.coordinates(txtwaypoints), ), ), wfolder, pfolder, vfolder, KML.Placemark( KML.name('Smooth Flight Path'), KML.visibility(1), KML.styleUrl('#smoothstyle'), KML.LineString( KML.extrude(1), KML.tessellate(1), KML.altitudeMode('absolute'), KML.coordinates(txtsmoothed), ), ), ), )) for wp in self.smoothed: playlist.append( GX.FlyTo( GX.duration(wp.LegTime), GX.flyToMode('smooth'), KML.Camera( KML.latitude(wp.Latitude), KML.longitude(wp.Longitude), KML.altitude(wp.Altitude), KML.heading(wp.Heading), KML.tilt(wp.GimbalTilt), KML.roll(0), KML.altitudeMode("absolute"), GX.horizFov(self.hfov), ), ), ) playlist.append(GX.Wait(GX.duration(0), ), ) for wp in self.waypoints: wfolder.append( KML.Placemark( KML.name('WP%02d' % (wp.Num)), KML.visibility(1), KML.styleUrl('#wpmarkers'), KML.ExtendedData( KML.Data(KML.value(wp.Num), name='Waypoint'), KML.Data(KML.value(round(wp.Altitude, 0)), name='Altitude_Abs'), KML.Data(KML.value(round(wp.Altitude - wp.GroundAlt, 0)), name='Altitude_Gnd'), KML.Data(KML.value(round(wp.Heading, 0)), name='Heading'), KML.Data(KML.value(round(wp.GimbalTilt - 90.0, 0)), name='Gimbal'), ), KML.Point( KML.altitudeMode("absolute"), KML.extrude(1), KML.coordinates( '%f,%f,%f' % (wp.Longitude, wp.Latitude, wp.Altitude)), ), ), ) for poi in self.pois: num = self.pois.index(poi) + 1 pfolder.append( KML.Placemark( KML.name('POI%02d' % num), KML.visibility(1), KML.styleUrl('#poimarkers'), KML.ExtendedData( KML.Data(KML.value(num), name='POI'), KML.Data(KML.value(round(poi.Altitude, 0)), name='Altitude_Abs'), KML.Data(KML.value( round(poi.Altitude - poi.GroundAlt, 0)), name='Altitude_Gnd'), ), KML.Point( KML.altitudeMode("absolute"), KML.extrude(1), KML.coordinates( '%f,%f,%f' % (poi.Longitude, poi.Latitude, poi.Altitude)), ), ), ) for wp in self.smoothed: if wp.Num is None: continue vfolder.append( KML.Document( KML.name('WP%03d' % (wp.Num)), KML.visibility(0), KML.Camera( KML.latitude(wp.Latitude), KML.longitude(wp.Longitude), KML.altitude(wp.Altitude), KML.heading(wp.Heading), KML.tilt(wp.GimbalTilt), KML.roll(0), KML.altitudeMode("absolute"), GX.horizFov(self.hfov), ), ), ) return etree.tostring(virtmission, pretty_print=True)