Example #1
0
 def update_kml(self, request, response):
   change = KML.Change()
   create = KML.Create()
   delete = KML.Delete()
   doc = KML.Document(targetId=KmlPlacemark.DOC_ID)
   for id_, kpm in self.placemarks.items():
     if kpm.is_new:
       style_url = KmlStyleUtils.get_style_url_for_callsign(kpm.callsign)
       model_url = None # KmlStyleUtils.get_model_url_for_callsign(kpm.callsign, request.host_url)
       placemark = kpm.get_placemark(style_url, model_url)
       doc.append(placemark)
       kpm.is_new = False
     else:
       kpm.generate_update(change = change, create = create, delete = delete)
   if doc.countchildren() > 0:
     create.append(doc)
   update = KML.Update(KML.targetHref(request.path_url))
   if change.countchildren() > 0:
     update.append(change)
   if create.countchildren() > 0:
     update.append(create)
   if delete.countchildren() > 0:
     update.append(delete)
   network_link_control = KML.NetworkLinkControl(update)
   return KML.kml(network_link_control)
Example #2
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
Example #3
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)
Example #4
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))
Example #5
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
Example #6
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)