示例#1
0
    def rotation_around_placemark(self, data, params, kml_doc):
        if type(data) is list:
            print("list")
            longitude = data[0]
            latitude = data[1]
        else:
            longitude = data.longitude
            latitude = data.latitude

        # spin around the data
        for aspect in range(0, 360, 10):
            kml_doc.Document[gxns + "Tour"].Playlist.append(
                GX.FlyTo(
                GX.duration(params[0]),
                    GX.flyToMode("smooth"),
                    KML.LookAt(
                        KML.longitude(float(longitude)),
                        KML.latitude(float(latitude)),
                        KML.altitude(params[1]),
                        KML.heading(aspect),
                        KML.tilt(params[2]),
                        KML.range(params[3]),
                        KML.altitudeMode("relativeToGround"),
                    )
                )
            )

        kml_doc.Document[gxns + "Tour"].Playlist.append(GX.Wait(GX.duration(1.0)))

        return kml_doc
示例#2
0
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'])))
示例#3
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>'
     )
示例#4
0
    def generateKML_Line_Track_Experience (self,data_points):
        linetrack_experience_kml_doc = self.KML_file_header(["",""],"Line Track Experience")

        longitude = str(data_points[0]).split(",")[0].split("['")[1]
        latitude = str(data_points[0]).split(",")[1].split("']")[0]
        linetrack_experience_kml_doc = self.find_to_stand_over_the_placemark(2.0,longitude,latitude,linetrack_experience_kml_doc)

        i = 0
        while i < len(data_points)-1:
            data_list = []
            data_list.append(str(data_points[i]).split(",")[0].split("['")[1])
            data_list.append(str(data_points[i]).split(",")[1].split("']")[0])
            data_list.append(str(data_points[i+1]).split(",")[0].split("['")[1])
            data_list.append(str(data_points[i+1]).split(",")[1].split("']")[0])
            iid = str((i+1))
            linetrack_experience_kml_doc = self.add_placemark_simple_line(data_list,iid,linetrack_experience_kml_doc)

            i = i+1

        i = 0
        while i < len(data_points)-1:
            linetrack_experience_kml_doc.Document[gxns + "Tour"].Playlist.append(GX.Wait(GX.duration(0.06)))

            linetrack_experience_kml_doc.Document[gxns + "Tour"].Playlist.append(
                GX.AnimatedUpdate(
                    KML.Update(
                        KML.Change(
                            KML.Placemark(
                                KML.visibility(1),
                                targetId=str((i+1)),
                            )
                        )
                    )
                )
            )

            i = i+1

        return self.save_kml_file(self.kml_name, linetrack_experience_kml_doc)
示例#5
0
    def show_placemark_balloon(self, duration, target, kml_doc):
        # show the placemark balloon

        kml_doc.Document[gxns + "Tour"].Playlist.append(
            GX.AnimatedUpdate(
                GX.duration(1.0),
                KML.Update(
                    KML.targetHref(),
                    KML.Change(
                        KML.Placemark(
                            KML.visibility(1),
                            GX.balloonVisibility(1),
                            targetId=target.replace(' ', '_')
                        )
                    )
                )
            )
        )

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

        kml_doc.Document[gxns + "Tour"].Playlist.append(
            GX.AnimatedUpdate(
                GX.duration(0.5),
                KML.Update(
                    KML.targetHref(),
                    KML.Change(
                        KML.Placemark(
                            GX.balloonVisibility(0),
                            targetId=target.replace(' ', '_')
                        )
                    )
                )
            )
        )

        return kml_doc
示例#6
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))
示例#7
0
            )), )
    # spin around the feature
    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(feature['lon']),
                    KML.latitude(feature['lat']),
                    KML.altitude(0),
                    KML.heading(aspect),
                    KML.tilt(feature['tilt']),
                    KML.range(feature['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 feature
    tour_doc.Document.Folder.append(
        KML.Placemark(KML.name("?"),
                      KML.description("<h1>{name}</h1><br/>{desc}".format(
                          name=feature['name'],
                          desc=feature['desc'],
                      )),
                      KML.Point(
                          KML.extrude(1), KML.altitudeMode("relativeToGround"),
                          KML.coordinates("{lon},{lat},{alt}".format(
示例#8
0
            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))

schema = Schema('kml22gx.xsd')
import ipdb
ipdb.set_trace()
schema.validate(doc)
示例#9
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)