示例#1
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'])))
示例#2
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
示例#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 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
示例#5
0
    def get_away_from_placemark(self, data, kml_doc):
        # fly to a space viewpoint. Allunyar-se de la ciutat per buscar el seguent punt
        kml_doc.Document[gxns + "Tour"].Playlist.append(
            GX.FlyTo(
                GX.duration(8.0),
                GX.flyToMode("bounce"),
                KML.LookAt(
                    KML.longitude(float(data.longitude)),
                    KML.latitude(float(data.latitude)),
                    KML.altitude(0),
                    KML.heading(0),
                    KML.tilt(0),
                    KML.range(self.range),
                    KML.altitudeMode("relativeToGround"),
                )
            ),
        )

        return kml_doc
示例#6
0
    def find_to_stand_over_the_placemark(self, duration, longitude, latitude, kml_doc):
        # rota fins estar a sobre de la ciutat i apropar-se
        kml_doc.Document[gxns + "Tour"].Playlist.append(
            GX.FlyTo(
                GX.duration(duration),
                GX.flyToMode("smooth"),
                KML.LookAt(
                    KML.longitude(longitude),
                    KML.latitude(latitude),
                    KML.altitude(0),
                    KML.heading(0),
                    KML.tilt(0),
                    KML.range(self.range),
                    KML.altitudeMode("relativeToGround"),
                )
            ),
        )

        return kml_doc
示例#7
0
    def fly_to_the_placemark(self, longitude, latitude, params, mode, kml_doc):
        # fly to the data
        kml_doc.Document[gxns + "Tour"].Playlist.append(
            GX.FlyTo(
                GX.duration(params[0]),
                GX.flyToMode(mode),
                KML.LookAt(
                    KML.longitude(longitude),
                    KML.latitude(latitude),
                    KML.altitude(params[1]),
                    KML.heading(params[2]),
                    KML.tilt(params[3]),
                    KML.name(params[4].upper()),
                    KML.range(params[5]),
                    KML.altitudeMode("relativeToGround"),
                )
            ),
        )

        return kml_doc
示例#8
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))
示例#9
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))
示例#10
0
        ),
        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']),
                KML.altitude(0),
                KML.heading(0),
                KML.tilt(0),
                KML.range(10000000.0),
                KML.altitudeMode("relativeToGround"),
            )), )
    # fly to the feature
    tour_doc.Document[gxns + "Tour"].Playlist.append(
        GX.FlyTo(
            GX.duration(5), GX.flyToMode("bounce"),
            KML.LookAt(
                KML.longitude(feature['lon']),
                KML.latitude(feature['lat']),
                KML.altitude(0),
                KML.heading(0),
                KML.tilt(feature['tilt']),
示例#11
0
            id="mystyle"),
                  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))
示例#12
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))
示例#13
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)