Exemple #1
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
Exemple #2
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))
Exemple #3
0
                          KML.extrude(1), KML.altitudeMode("relativeToGround"),
                          KML.coordinates("{lon},{lat},{alt}".format(
                              lon=feature['lon'],
                              lat=feature['lat'],
                              alt=50,
                          ))),
                      id=feature['name'].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=feature['name'].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=feature['name'].replace(' ',
                                                                   '_'))))))
    # fly to a space viewpoint
                )
                )
            ),
            id=feature['name'].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=feature['name'].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(
Exemple #5
0
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
Exemple #6
0
           )
       )
     ),
     id=feature['name'].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=feature['name'].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(