Example #1
0
def Camera(Ddeploy):
    # generate the camera tree

    # If XML had lat,lon for deployment location, use that.  Otherwise, use generic
    lat = str(checkNone(Ddeploy['latitude'], 71.61020799525069))
    lon = str(checkNone(Ddeploy['longitude'], -161.9384752350831))
    camera = K.Camera(
        K.longitude(lon),
        K.latitude(lat),
        K.altitude("500000"),
        K.heading("0"),
        K.tilt("0"),
        K.roll("0"),
        K.altitudeMode("absolute"),
    )
    return camera
Example #2
0
def create_flyto_camera(location):

    flyto = GX.FlyTo(
        GX.duration(0.5),
        GX.flyToMode('smooth'),
    )
    flyto.append(
        KML.Camera(
            KML.longitude(location['loc'].longitude),
            KML.latitude(location['loc'].latitude),
            KML.altitude(location['loc'].altitude),
            KML.heading(location['loc'].heading),
            KML.tilt(location['loc'].tilt),
            KML.roll(location['loc'].roll),
            KML.altitudeMode('relativeToGround'),
        ))
    return flyto
Example #3
0
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)

    flyto = gx.FlyTo(
        gx.duration(tstep), gx.flyToMode("smooth"),
        kml.Camera(
            kml.longitude(loc0['longitude'] + vx * t),
            kml.latitude(loc0['latitude'] + vy * t),
            kml.altitude(loc0['altitude'] + vz * t + 0.5 * g * t**2),
            kml.heading(loc0['heading'] + vh * t),
            kml.tilt(loc0['tilt'] + vt * t),
            kml.altitudeMode("absolute"),
        ))
    tour_doc.Folder[GX_ns + "Tour"].Playlist.append(flyto)

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(__file__.rstrip('.py') + '.kml', 'w')
outfile.write(etree.tostring(tour_doc, pretty_print=True))
Example #4
0
                  id="pushpin"),
        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)
Example #5
0
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),
          KML.latitude(lat),
          KML.altitude(0),
          KML.heading(-129.7),
          KML.tilt(90.0),
          KML.altitudeMode("relativeToGround"),
        )
    )
    tour_doc[gxns+"Tour"].Playlist.append(flyto)

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(__file__.rstrip('.py')+'.kml','w')
outfile.write(etree.tostring(tour_doc, pretty_print=True))
Example #6
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)