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)) data = etree.tostring(doc, encoding='ascii') expected = \ b'<kml xmlns:gx="http://www.google.com/kml/ext/2.2" ' \ b'xmlns:atom="http://www.w3.org/2005/Atom" ' \ b'xmlns="http://www.opengis.net/kml/2.2">' \ b'<gx:Tour>' \ b'<gx:Playlist>' \ b'<gx:SoundCue>' \ b'<href>http://dev.keyhole.com/codesite/cntowerfacts.mp3</href>' \ b'</gx:SoundCue>' \ b'<gx:Wait>' \ b'<gx:duration>10</gx:duration>' \ b'</gx:Wait>' \ b'<gx:FlyTo>' \ b'<gx:duration>5</gx:duration>' \ b'<gx:flyToMode>bounce</gx:flyToMode>' \ b'<LookAt>' \ b'<longitude>-79.387</longitude>' \ b'<latitude>43.643</latitude>' \ b'<altitude>0</altitude>' \ b'<heading>-172.3</heading>' \ b'<tilt>10</tilt>' \ b'<range>1200</range>' \ b'<altitudeMode>relativeToGround</altitudeMode>' \ b'</LookAt>' \ b'</gx:FlyTo>' \ b'</gx:Playlist>' \ b'</gx:Tour>' \ b'</kml>' self.assertXmlEquivalentOutputs(data, expected)
def kml_addPathPoint(self, pos, dt): #pos[0] : latitude #pos[1] : longitude #pos[2] : altitude #pos[3] : roll #pos[4] : pitch #pos[5] : yaw if (pos == None): return #rospy.logerr(pos) self.tour_doc.Document[self.gxns+"Tour"].Playlist.append( GX.FlyTo( GX.duration(dt), GX.flyToMode("smooth"), #KML.Camera( KML.LookAt( KML.latitude(pos[0]), KML.longitude(pos[1]), KML.altitude(pos[2]), KML.heading(pos[5]), #KML.tilt(pos[4] + 90.0), #KML.roll(pos[3]), KML.tilt(pos[4] + 75.0), KML.range(20.0), KML.altitudeMode("absolute"), ), ), ) auxStr = ' {lon},{lat},{alt}\n'.format(lon=pos[1], lat=pos[0], alt=pos[2]) #rospy.logerr(auxStr) self.execCoordListStr = self.execCoordListStr + auxStr
def create_tour_doc(tour_doc, row, imageInterval): camHeight = row['Z'] longitude, latitude = myProj(row['X'], row['Y'], inverse = True) azimuth = row['azimuth'] zenith = row['zenith'] intervalNo = row['intervalNo'] corrChunk = imageInterval[int(intervalNo)] # define a variable for the Google Extensions namespace URL string gxns = '{' + nsmap['gx'] + '}' #fly to the subChunk with the given subChunk parameters tour_doc.Document[gxns+"Tour"].Playlist.append( GX.FlyTo( GX.flyToMode("bounce"), KML.LookAt( KML.longitude(longitude),#change chunk[] to subChunk from csv KML.latitude(latitude),#change chunk[] to subChunk from csv KML.altitude(camHeight),#change chunk[] to subChunk from csv KML.heading(azimuth),#change chunk[] to subChunk from csv KML.tilt(zenith),#change chunk[] to subChunk from csv KML.range(corrChunk['range0']),#change all chunk[] to subChunk from csv KML.altitudeMode(corrChunk['altitudeMode']), GX.horizFov(horizFov) ) ) ) tour_doc.Document[gxns+"Tour"].Playlist.append(GX.Wait(GX.duration(corrChunk['lookAtDuration'])))
def 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
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>' )
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
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
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
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
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
def make_kml(self, lon, lat): """ :return: write kml file from defined properties """ doc = KML.kml( etree.Comment(' required when using gx-prefixed elements '), GX.FlyTo( GX.flyToMode('bounce'), GX.duration('0.5') ), KML.Placemark( KML.name('gx:altitudeMode Example'), KML.Camera( KML.altitude(self.vh), KML.longitude(str(lon)), KML.latitude(str(lat)) ), ), ) string = etree.tostring(etree.ElementTree(doc),pretty_print=True) #writeToFile f = open(self.outfile, 'w') f.writelines(string) f.close()
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))
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),
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']), 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']),
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)
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), 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')
KML.href( "http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png" ), ), 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))))))
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']), 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),
) ) 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)
def create_kml_tour(addresses, filename): ''' Creates a kml tour of the sites Modified from pykml example here https://pythonhosted.org/pykml/examples/tour_examples.html python Generate a KML document of a tour based on rotating around locations. ''' tilt = 20 distance = 20 # define a variable for the Google Extensions namespace URL string gxns = '{' + nsmap['gx'] + '}' # 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('Sites'), id='sites', ), ) ) for address in addresses: #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(address['longitude']), KML.latitude(address['latitude']), KML.altitude(0), KML.heading(0), KML.tilt(0), KML.range(10000000.0), KML.altitudeMode("relativeToGround"), ) ), ) # fly to the address tilt = tilt + 10 distance = distance + 10 tour_doc.Document[gxns+"Tour"].Playlist.append( GX.FlyTo( GX.duration(0.25), GX.flyToMode("smooth"), KML.LookAt( KML.longitude(address['longitude']), KML.latitude(address['latitude']), KML.altitude(0), KML.heading(0), ## KML.tilt(address['tilt']), ## KML.range(address['range']), KML.tilt(tilt), KML.range(distance), KML.altitudeMode("relativeToGround"), ) ), ) # add a placemark for the address tour_doc.Document.Folder.append( KML.Placemark( KML.name("?"), KML.description( "<h1>{name}</h1><br/>{desc}".format( name=address['Site'], desc=address['Bandwidth'], ) ), KML.Point( KML.extrude(1), KML.altitudeMode("relativeToGround"), KML.coordinates("{lon},{lat},{alt}".format( lon=address['longitude'], lat=address['latitude'], alt=50, ) ) ), id=address['Site'].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=address['Site'].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=address['Site'].replace(' ','_') ) ) ) ) ) # spin around the address 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(address['longitude']), KML.latitude(address['latitude']), KML.altitude(0), KML.heading(aspect), KML.tilt(tilt), KML.range(distance), KML.altitudeMode("relativeToGround"), ) ) ) for angle 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(address['longitude']), KML.latitude(address['latitude']), KML.altitude(0), KML.heading(angle), ## KML.tilt(address['tilt']), ## KML.range(address['range']), KML.tilt(tilt), KML.range(distance), 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")) # ) # fly to a space viewpoint tour_doc.Document[gxns+"Tour"].Playlist.append( GX.FlyTo( GX.duration(5), GX.flyToMode("bounce"), KML.LookAt( KML.longitude(address['longitude']), KML.latitude(address['latitude']), 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)) #always bombs # print etree.tostring(tour_doc, pretty_print=True) # output a KML file (named based on the Python script) outfile = kmlfile + '_tour.kml' with open(outfile,'w') as file: file.write(etree.tostring(tour_doc, pretty_print=True)) return
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) 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')
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, encoding='utf-8',
def __tour__(self): # Define a variable for the Google Extensions namespace URL string gxns = '{' + nsmap['gx'] + '}' tour = GX.Tour(KML.name('Play me!'), GX.Playlist()) tour.Playlist.append( GX.FlyTo( GX.duration(5), GX.flyToMode('smooth'), KML.LookAt( KML.longitude(-45), KML.latitude(-43), KML.altitude(0), KML.heading(355), KML.tilt(55), KML.range(6000000.0), KML.altitudeMode('absolute')))) tour.Playlist.append( GX.FlyTo( GX.duration(10), GX.flyToMode('smooth'), KML.LookAt( KML.longitude(-80), KML.latitude(63), KML.altitude(0), KML.heading(345), KML.tilt(45), KML.range(10000000.0), KML.altitudeMode('absolute')))) tour.Playlist.append( GX.FlyTo( GX.duration(10), GX.flyToMode('smooth'), KML.LookAt( KML.longitude(-131), KML.latitude(63), KML.altitude(0), KML.heading(345), KML.tilt(35), KML.range(20000000.0), KML.altitudeMode('absolute')))) tour.Playlist.append( GX.FlyTo( GX.duration(5), GX.flyToMode('smooth'), KML.LookAt( KML.longitude(53), KML.latitude(25), KML.altitude(0), KML.heading(270), KML.tilt(35), KML.range(20000000.0), KML.altitudeMode('absolute')))) tour.Playlist.append( GX.FlyTo( GX.duration(10), GX.flyToMode('smooth'), KML.LookAt( KML.longitude(140), KML.latitude(-4), KML.altitude(0), KML.heading(0), KML.tilt(55), KML.range(10000000.0), KML.altitudeMode('absolute')))) return 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']), 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),