def run(self): for index in xrange(len(self.flist)): time.sleep(6) datafile = self.flist[index] print datafile addfile(datafile,'localhost',8000) return
def createkml(self,collections, fname): self.lk_heading = -34.82469740081282 self.lk_tilt = 53.454348562403 self.lk_range = 276.7870053764046 kmls1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><name>newkml</name><open>0</open><description>laeltets</description><Style id=\"Mystyle\"><LabelStyle><color>ff81ff75</color><colorMode>normal</colorMode><scale>1</scale></LabelStyle><IconStyle><Icon><href>/code/planetsasha/icons/blue_circle.png</href></Icon></IconStyle><LineStyle><color>ff3776ff</color><colorMode>normal</colorMode><tessellate>0</tessellate><width>0</width></LineStyle><PolyStyle><color>ff9646ff</color><colorMode>normal</colorMode></PolyStyle></Style>" self.lk_lat = 0 self.lk_lon = 0 for col in collections: p = col.get_paths()[0] if len(p.vertices) > 0: self.lk_lat = p.vertices[0][0] self.lk_lon = p.vertices[0][1] break #print self.lk_lat #sys.exit(1) #self.init_kml() self.kmlstr2 = "\n<Folder>\ <name>ocean_model</name>\ <visibility>0</visibility>\ <description>empty</description>\ <LookAt>\ <longitude>%s</longitude><latitude>%s</latitude>\ <altitude>0</altitude><heading>%s</heading><tilt>%s</tilt><range>%s</range> \ </LookAt>\ \n<Placemark>\ <name>Building 40</name>\ <visibility>0</visibility>\ <styleUrl>#Mystyle</styleUrl>" %( str(self.lk_lat), str(self.lk_lon), str(self.lk_heading), str(self.lk_tilt), str(self.lk_range)) ##for vert in p.vertices: ##self.outkml = self.kmlstr1 + self.kmlstr2 + self.kmlstr3 + self.kmlstr4 ##print self.outkml for col in collections: p = col.get_paths()[0] self.kmlstr3 = "\n<Polygon><extrude>1</extrude><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><coordinates>" if len(p.vertices) > 0: #print len(p) vert = p.vertices #print len(vert) for v in vert: x = str(v[0]) y = str(v[1]) self.kmlstr3 = self.kmlstr3 + x+ "," + y + ",17 \n" self.kmlstr5 = "</coordinates></LinearRing></outerBoundaryIs></Polygon>" #print x + " " + y #e() #self.add_data(x,y) #print "collection: " + str(k) #print str(x) + " " + str(y) #k = k+1 #break #print self.lyr.GetFeatureCount() kmltail = "</Placemark></Folder></Document></kml>" outkml = kmls1 + self.kmlstr2 + self.kmlstr3 + self.kmlstr5 + kmltail f=codecs.open(fname, 'w', 'UTF8' ) f.write(outkml) f.close() addfile(fname,'localhost',8000)