6 from pprint import pprint
8 def queue_render(db,filename):
10 conn = sqlite3.connect(db)
13 cur.execute("select minlat,minlon,maxlat,maxlon from tracks where filename=?" , (filename.decode('UTF-8'),))
15 minlat,minlon,maxlat,maxlon=cur.fetchone()
17 # определяем примерный стартовый зум
19 minlatrad = math.radians(minlat)
20 maxlatrad = math.radians(maxlat)
22 minx = (minlon + 180.0)/360.0
23 maxx = (maxlon + 180.0)/360.0
25 miny = (1.0 - math.log(math.tan(minlatrad) + (1 / math.cos(minlatrad))) / math.pi) / 2.0
26 maxy = (1.0 - math.log(math.tan(maxlatrad) + (1 / math.cos(maxlatrad))) / math.pi) / 2.0
34 for zoom in range(9,16):
44 print zoom,minxt,maxxt,minyt,maxyt
45 ins.execute('insert into render_queue(zoom,minx,maxx,miny,maxy) values(?,?,?,?,?)',(zoom,minxt,maxxt,minyt,maxyt))
47 if (maxxt-minxt>16) or (maxyt-minyt>12):
53 def process_queue(db,map):
57 conn = sqlite3.connect(db)
59 cur.execute('select id,zoom,minx,maxx,miny,maxy from render_queue')
64 id,zoom,minx,maxx,miny,maxy=rec
66 command = 'render_list -a -m '+map+ \
67 ' -z '+str(zoom)+' -Z '+str(zoom)+ \
68 ' -x '+str(minx)+' -X '+str(maxx)+ \
69 ' -y '+str(miny)+' -Y '+str(maxy)
70 if system(command)==0:
72 dcur.execute('delete from render_queue where id=?',(id,))
77 from optparse import OptionParser
79 parser = OptionParser()
80 parser.add_option("-d", "--data", dest="directory",
81 help="Data directory", metavar="DIR")
82 parser.add_option("-m", "--map", dest="map",
83 help="Map name", metavar="MAP")
84 (options, args) = parser.parse_args()
86 db=options.directory+'/gpx.db'
91 if __name__ == "__main__":