示例#1
0
 def test_basic_kml_document(self):
     """Tests the creation of a basic KML with Google Extensions ."""
     doc = KML.kml(
         GX.Tour(
             GX.Playlist(
                 GX.SoundCue(
                     KML.href("http://dev.keyhole.com/codesite/cntowerfacts.mp3")
                 ),
                 GX.Wait(
                     GX.duration(10)
                 ),
                 GX.FlyTo(
                     GX.duration(5),
                     GX.flyToMode("bounce"),
                     KML.LookAt(
                         KML.longitude(-79.387),
                         KML.latitude(43.643),
                         KML.altitude(0),
                         KML.heading(-172.3),
                         KML.tilt(10),
                         KML.range(1200),
                         KML.altitudeMode("relativeToGround"),
                     )
                 )
             )
         )
     )
     self.assertTrue(Schema("kml22gx.xsd").validate(doc))
     self.assertEqual(
         etree.tostring(doc).decode(),
         '<kml '
              'xmlns:atom="http://www.w3.org/2005/Atom" '
              'xmlns:gx="http://www.google.com/kml/ext/2.2" '
              'xmlns="http://www.opengis.net/kml/2.2">'
           '<gx:Tour>'
             '<gx:Playlist>'
               '<gx:SoundCue>'
                 '<href>http://dev.keyhole.com/codesite/cntowerfacts.mp3</href>'
               '</gx:SoundCue>'
               '<gx:Wait>'
                 '<gx:duration>10</gx:duration>'
               '</gx:Wait>'
               '<gx:FlyTo>'
                 '<gx:duration>5</gx:duration>'
                 '<gx:flyToMode>bounce</gx:flyToMode>'
                 '<LookAt>'
                   '<longitude>-79.387</longitude>'
                   '<latitude>43.643</latitude>'
                   '<altitude>0</altitude>'
                   '<heading>-172.3</heading>'
                   '<tilt>10</tilt>'
                   '<range>1200</range>'
                   '<altitudeMode>relativeToGround</altitudeMode>'
                 '</LookAt>'
               '</gx:FlyTo>'
             '</gx:Playlist>'
           '</gx:Tour>'
         '</kml>'
     )
示例#2
0
def init_kml(KMLname):
    # start with a base KML tour and playlist
    tour_doc = KML.kml(
        KML.Document(
          GX.Tour(
            KML.name(KMLname),
            GX.Playlist(),
    		),
        )
    )
    return tour_doc
示例#3
0
z0 = loc0['altitude']
z1 = loc1['altitude']
deltat = (-vz - math.sqrt(vz**2 - 2 * g * (z0 - z1))) / g
deltat = 30  # set manually, not sure what is wrong with the previous eqn

#import ipdb; ipdb.set_trace()

# calculate the horizontal and rotational velocities
vy = (loc1['latitude'] - loc0['latitude']) / deltat
vx = (loc1['longitude'] - loc0['longitude']) / deltat
vh = (loc1['heading'] - loc0['heading']) / deltat
vt = (loc1['tilt'] - loc0['tilt']) / deltat

# create a tour object
tour_doc = kml.kml(kml.Folder(gx.Tour(
    kml.name("Play me!"),
    gx.Playlist(),
)))

tstep = 0.1
for t in drange(0, 15, tstep):
    pm = kml.Placemark(
        kml.name(str(t)),
        kml.Point(
            kml.altitudeMode("absolute"),
            kml.coordinates("{lon},{lat},{alt}".format(
                lon=loc0['longitude'] + vx * t,
                lat=loc0['latitude'] + vy * t,
                alt=loc0['altitude'] + vz * t + 0.5 * g * t**2,
            )),
        ))
    tour_doc.Folder.append(pm)
示例#4
0
    def makeFile(self):


        # define a variable for the Google Extensions namespace URL string
        gxns = '{' + nsmap['gx'] + '}'

        stylename = "sn_shaded_dot"
        # start with a base KML tour and playlist
        tour_doc = KML.kml(
            KML.Document(
                GX.Tour(
                    KML.name("Play me!"),
                    GX.Playlist(),
                ),
                KML.Folder(
                    KML.name('Features'),
                    id='features',
                ),
                KML.Style(
                    KML.IconStyle(
                        KML.scale(1.2),
                        KML.Icon(
                            KML.href(self.icon)
                        ),
                    ),
                    id=stylename,
                )
            )
        )
        for data in self.data_set:
            # import ipdb; ipdb.set_trace()
            # fly to a space viewpoint
            tour_doc.Document[gxns + "Tour"].Playlist.append(
                GX.FlyTo(
                    GX.duration(5),
                    GX.flyToMode("smooth"),
                    KML.LookAt(
                        KML.longitude(float(data['coordinates']['lng'])),
                        KML.latitude(float(data['coordinates']['lat'])),
                        KML.altitude(0),
                        KML.heading(0),
                        KML.tilt(0),
                        KML.range(10000000.0),
                        KML.altitudeMode("relativeToGround"),
                    )
                ),
            )
            # fly to the data
            tour_doc.Document[gxns + "Tour"].Playlist.append(
                GX.FlyTo(
                    GX.duration(5),
                    GX.flyToMode("bounce"),
                    KML.LookAt(
                        KML.longitude(float(data['coordinates']['lng'])),
                        KML.latitude(float(data['coordinates']['lat'])),
                        KML.altitude(0),
                        KML.heading(0),
                        KML.tilt(data['data']),
                        KML.name(data['data']),
                        KML.range(self.range),
                        KML.altitudeMode("relativeToGround"),
                    )
                ),
            )
            # spin around the data
            for aspect in range(0, 360, 10):
                tour_doc.Document[gxns + "Tour"].Playlist.append(
                    GX.FlyTo(
                        GX.duration(0.25),
                        GX.flyToMode("smooth"),
                        KML.LookAt(
                            KML.longitude(float(data['coordinates']['lng'])),
                            KML.latitude(float(data['coordinates']['lat'])),
                            KML.altitude(0),
                            KML.heading(aspect),
                            KML.tilt(data['data']),
                            KML.name(data['data']),
                            KML.range(self.range),
                            KML.altitudeMode("relativeToGround"),
                        )
                    )
                )
            tour_doc.Document[gxns + "Tour"].Playlist.append(GX.Wait(GX.duration(1.0)))

            # tour_doc.Document[gxns+"Tour"].Playlist.append(
            #        GX.TourControl(GX.playMode("pause"))
            #    )

            # add a placemark for the data
            tour_doc.Document.Folder.append(
                KML.Placemark(
                    KML.name(data['data']),
                    KML.description(
                        "<h1>" + data['data'] + "</h1>"
                    ),
                    KML.styleUrl('#{0}'.format(stylename)),
                    KML.Point(
                        KML.extrude(1),
                        KML.altitudeMode("relativeToGround"),
                        KML.coordinates("{lon},{lat},{alt}".format(
                            lon=float(data['coordinates']['lng']),
                            lat=float(data['coordinates']['lat']),
                            alt=50,
                        )
                        )
                    ),
                    id=data['data'].replace(' ', '_')
                )
            )
            # show the placemark balloon
            tour_doc.Document[gxns + "Tour"].Playlist.append(
                GX.AnimatedUpdate(
                    GX.duration(2.0),
                    KML.Update(
                        KML.targetHref(),
                        KML.Change(
                            KML.Placemark(
                                KML.visibility(1),
                                GX.balloonVisibility(1),
                                targetId=data['data'].replace(' ', '_')
                            )
                        )
                    )
                )
            )

            tour_doc.Document[gxns + "Tour"].Playlist.append(GX.Wait(GX.duration(2.0)))

            tour_doc.Document[gxns + "Tour"].Playlist.append(
                GX.AnimatedUpdate(
                    GX.duration(2.0),
                    KML.Update(
                        KML.targetHref(),
                        KML.Change(
                            KML.Placemark(
                                GX.balloonVisibility(0),
                                targetId=data['data'].replace(' ', '_')
                            )
                        )
                    )
                )
            )
            # fly to a space viewpoint
            tour_doc.Document[gxns + "Tour"].Playlist.append(
                GX.FlyTo(
                    GX.duration(5),
                    GX.flyToMode("bounce"),
                    KML.LookAt(
                        KML.longitude(float(data['coordinates']['lng'])),
                        KML.latitude(float(data['coordinates']['lat'])),
                        KML.altitude(0),
                        KML.heading(0),
                        KML.tilt(0),
                        KML.range(10000000.0),
                        KML.altitudeMode("relativeToGround"),
                    )
                ),
            )

        # check that the KML document is valid using the Google Extension XML Schema
        # assert(Schema("kml22gx.xsd").validate(tour_doc))

        # print etree.tostring(tour_doc, pretty_print=True)

        # output a KML file (named based on the Python script)
        outfile = file("kmls_management/static/" + self.kml_name, 'w')
        outfile.write(etree.tostring(tour_doc, pretty_print=True))
示例#5
0
        'range': 8000
    },
    {
        'name': "Matterhorn",
        'desc': 'Pennine Alps, Switzerland/Italy',
        'lon': 7.6584,
        'lat': 45.9766,
        'tilt': 60,
        'range': 6000,
    },
]
# start with a base KML tour and playlist
tour_doc = KML.kml(
    KML.Document(
        GX.Tour(
            KML.name("Play me!"),
            GX.Playlist(),
        ),
        KML.Folder(
            KML.name('Features'),
            id='features',
        ),
    ))
for feature in feature_list:
    #import ipdb; ipdb.set_trace()
    # fly to a space viewpoint
    tour_doc.Document[gxns + "Tour"].Playlist.append(
        GX.FlyTo(
            GX.duration(5), GX.flyToMode("smooth"),
            KML.LookAt(
                KML.longitude(feature['lon']),
                KML.latitude(feature['lat']),
示例#6
0
def main():
    known_positions = [
        # outside GWC-1
        {
            'loc':
            Location(
                longitude=-122.0916728,
                latitude=37.42329373,
                altitude=2,
                heading=0,
                tilt=0,
                roll=0,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-01', '%Y-%m-%d'),
        },
        # over building
        {
            'loc':
            Location(
                longitude=-122.0905238,
                latitude=37.4222005,
                altitude=20,
                heading=92,
                tilt=80,
                roll=0,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-02', '%Y-%m-%d'),
        },
        # back to ground level
        {
            'loc':
            Location(
                longitude=-122.088513,
                latitude=37.4223038,
                altitude=2,
                heading=92,
                tilt=80,
                roll=0,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-03', '%Y-%m-%d'),
        },
        # under arch
        {
            'loc':
            Location(
                longitude=-122.087676,
                latitude=37.422365,
                altitude=5,
                heading=107,
                tilt=80,
                roll=0,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-04', '%Y-%m-%d'),
        },
        # around building
        {
            'loc':
            Location(
                longitude=-122.086997,
                latitude=37.422113,
                altitude=5,
                heading=179,
                tilt=90,
                roll=0,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-05', '%Y-%m-%d'),
        },
        # around building 2
        {
            'loc':
            Location(
                longitude=-122.0870075,
                latitude=37.421748,
                altitude=5,
                heading=181,
                tilt=90,
                roll=-60,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-06', '%Y-%m-%d'),
        },

        # around building (south side)
        {
            'loc':
            Location(
                longitude=-122.0875599,
                latitude=37.42149516,
                altitude=5,
                heading=270,
                tilt=90,
                roll=-60,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-07', '%Y-%m-%d'),
        },
        # around building 3
        {
            'loc':
            Location(
                longitude=-122.088148,
                latitude=37.422131,
                altitude=5,
                heading=369,
                tilt=90,
                roll=-60,
                range=25,
            ),
            'time':
            datetime.strptime('2011-01-08', '%Y-%m-%d'),
        },
    ]
    interp_positions = interpolate_location_series(
        known_positions,
        number_of_positions=100,
        #horizontal_interp_method='linear',
    )
    # create a folder of original placemarks
    fld1 = KML.Folder(KML.name('original'))
    for loc in known_positions:
        fld1.append(create_placemarks(loc))

    # create a folder of interpolated placemarks
    fld2 = KML.Folder(KML.name('interpolated'))
    for loc in interp_positions:
        fld2.append(create_placemarks(loc))

    # create a folder of models showing camera positions/orientations
    fld3 = KML.Folder(KML.name('cameras'))
    for loc in interp_positions:
        fld3.append(create_camera_model_placemark(loc))

    # create a tour of camera positions
    playlist = GX.Playlist()
    for loc in interp_positions:
        playlist.append(create_flyto_camera(loc))

    fld = KML.Folder(
        fld1,
        fld2,
        fld3,
        GX.Tour(playlist),
    )

    print(etree.tostring(fld, pretty_print=True))
示例#7
0
        KML.Placemark(KML.name("Pin on a mountaintop"),
                      KML.styleUrl("#pushpin"),
                      KML.Point(
                          KML.coordinates(170.1435558771009,
                                          -43.60505741890396, 0)),
                      id="mountainpin1"),
        GX.Tour(
            KML.name("Play me!"),
            GX.Playlist(
                GX.FlyTo(
                    GX.duration(3), GX.flyToMode("bounce"),
                    KML.Camera(
                        KML.longitude(170.157),
                        KML.latitude(-43.671),
                        KML.altitude(9700),
                        KML.heading(-6.333),
                        KML.tilt(33.5),
                    )),
                GX.AnimatedUpdate(
                    GX.duration(5),
                    KML.Update(
                        KML.targetHref(),
                        KML.Change(
                            KML.IconStyle(KML.scale(10.0),
                                          targetId="mystyle")))),
                GX.Wait(GX.duration(5))))))

print(etree.tostring(doc, pretty_print=True))

# output a KML file (named based on the Python script)
outfile = file(__file__.rstrip('.py') + '.kml', 'w')
outfile.write(etree.tostring(doc, pretty_print=True))
示例#8
0
    def KML_file_header(self, icon, tour_name):
        if tour_name == "Stadium Tour":
            icon_ok = icon[0]
        else:
            icon_ok = "../img/"+icon[0]

        kml_doc = KML.kml(
                     KML.Document(
                       KML.Style(
                         KML.IconStyle(
                           KML.scale('2.5'),
                           KML.Icon(
                             KML.href(icon_ok)
                           ),
                         ),
                         KML.LabelStyle(
                           KML.color("ff80ccff"),
                           KML.scale(2)
                         ),
                         KML.BalloonStyle(
                           KML.text("$[description]")
                         ),
                         KML.LineStyle(
                             KML.color('bf00aaff'),
                             KML.width(5)
                         ),
                         id=stylename
                       ),
                       KML.Style(
                         KML.IconStyle(
                           KML.scale('2.5'),
                           KML.Icon(
                             KML.href("../img/"+icon[1])
                           ),
                         ),
                         KML.LabelStyle(
                           KML.color("ff80ccff"),
                           KML.scale(4)
                         ),
                         KML.LineStyle(
                           KML.color('FFFF0000'),
                           GX.outerColor('FF4CBB17'),
                           GX.physicalWidth('25000'),
                           GX.outerWidth('0.40')
                        ),
                        id=stylename2
                       ),
                       GX.Tour(
                         KML.name(tour_name),
                         GX.Playlist(),
                       ),
                       KML.Folder(
                         KML.name('Features'),
                         KML.Style(
                           KML.ListStyle(
                             KML.listItemType("checkHideChildren")
                           )
                         ),
                         id='features',
                       ),
                     ),
                  )

        return kml_doc
示例#9
0
    def KML_file_header_olympic_games(self):
        flags_list = []
        for country in self.data_set.medalTable:
            flags_list.append(country)

        kml_doc = KML.kml(
                    KML.Document(
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('3.5'),
                          KML.Icon(
                            KML.href("../img/"+str(self.data_set.year)+" Summer Olympics.png")
                          ),
                        ),
                        id=stylename_icon
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('3.5'),
                          KML.Icon(
                            KML.href("../img/flags/"+flags_list[0].replace(" ","")+".png")
                          ),
                        ),
                        id=stylename_icon_flags1
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('3.5'),
                          KML.Icon(
                            KML.href("../img/flags/"+flags_list[1].replace(" ","")+".png")
                          ),
                        ),
                        id=stylename_icon_flags2
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('3.5'),
                          KML.Icon(
                            KML.href("../img/flags/"+flags_list[2].replace(" ","")+".png")
                          ),
                        ),
                        id=stylename_icon_flags3
                      ),
                      KML.Style(
                        KML.LabelStyle(
                          KML.color("FFFFFFFF"),
                          KML.scale(1.75)
                        ),
                        KML.IconStyle(
                          KML.scale('3.5'),
                          KML.Icon(
                            KML.hide(True)
                          ),
                        ),
                        id=stylename_icon_label
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("ff793909"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("ff793909"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_first
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("ffee7920"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("ffee7920"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_second
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("fff3b17f"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("fff3b17f"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_third
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("ff00d7ff"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("ff00d7ff"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_golden
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("ffc0c0c0"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("ffc0c0c0"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_silver
                      ),
                      KML.Style(
                        KML.IconStyle(
                          KML.scale('4.0'),
                          KML.Icon(
                            KML.href("")
                          ),
                        ),
                        KML.LineStyle(
                          KML.color("ff53788c"),
                          KML.colorMode("normal"),
                          KML.width(5000),
                        ),
                        KML.PolyStyle(
                          KML.color("ff53788c"),
                          KML.colorMode("normal"),
                          KML.fill(1),
                          KML.outline(1),
                        ),
                        id=style_bronze
                      ),
                      GX.Tour(
                        KML.name("Tour Name"),
                        GX.Playlist(),
                      ),
                      KML.Folder(
                        KML.name('Features'),
                        id='features',
                      ),
                    )
                  )

        return kml_doc
示例#10
0
'''
from pykml.parser import parse
from pykml.factory import nsmap
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX
from pykml.parser import Schema
from lxml import etree

# define variables for the namespace URL strings
kmlns = '{}'  #'{' + nsmap['kml'] + '}'
gxns = '{' + nsmap['gx'] + '}'

# start with a base KML tour and playlist
tour_doc = KML.kml(GX.Tour(
    KML.name("Play me!"),
    GX.Playlist(),
))

with open("colorado_river_linestring.kml") as f:
    linestring_doc = parse(f)

# get the coordinate string of the first KML coordinate element
coord_str = str(linestring_doc.getroot().find(
    ".//{http://www.opengis.net/kml/2.2}coordinates")).strip()

for vertex in coord_str.split(' '):
    (lon, lat, alt) = vertex.split(',')
    flyto = GX.FlyTo(
        GX.duration(2), GX.flyToMode("smooth"),
        KML.Camera(
            KML.longitude(lon),
示例#11
0
    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)