6 from pprint import pprint
8 def queue_render(db,filename,forced_max_zoom=None):
10 conn = sqlite3.connect(db)
13 cur.execute("select minlat,minlon,maxlat,maxlon from tracks where filename=?" , (filename.decode('UTF-8'),))
14 minlat,minlon,maxlat,maxlon=cur.fetchone()
15 queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom)
17 def queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom=None):
19 conn = sqlite3.connect(db)
21 # определяем примерный стартовый зум
25 maxzoom=forced_max_zoom
30 print minlat,maxlat,minlon,maxlon,minzoom,maxzoom
31 ins.execute('insert into render_queue(minlat,maxlat,minlon,maxlon,minzoom,maxzoom) values(?,?,?,?,?,?)',(minlat,maxlat,minlon,maxlon,minzoom,maxzoom))
35 def process_queue(db,map,force=False):
39 conn = sqlite3.connect(db)
41 cur.execute('select id,minlat,maxlat,minlon,maxlon,minzoom,maxzoom from render_queue')
46 id,minlat,maxlat,minlon,maxlon,minzoom,maxzoom=rec
48 command = 'map='+map+ \
49 ' z='+str(minzoom)+'-'+str(maxzoom)+ \
50 ' lat='+str(minlat)+','+str(maxlat)+ \
51 ' lon='+str(minlon)+','+str(maxlon)
54 command = 'tirex-batch -n 0 '+command
56 command = 'tirex-batch -n 0 '+command+' -f not-exists'
60 if system(command)==0:
62 dcur.execute('delete from render_queue where id=?',(id,))
67 from optparse import OptionParser
69 parser = OptionParser()
70 parser.add_option("-d", "--data", dest="directory",
71 help="Data directory", metavar="DIR")
72 parser.add_option("-m", "--map", dest="map",
73 help="Map name", metavar="MAP")
74 parser.add_option("-z", "--zoom", dest="zoom",
75 help="Maximal zoom (forced), used with coordinates pairs (minlat minlon maxlat maxlon) or filename in arguments", metavar="MAP")
76 parser.add_option("-f", "--force", dest="force",
77 help="Force tile regeneration (on/off), default off")
78 (options, args) = parser.parse_args()
82 db=options.directory+'/gpx.db'
85 force=(options.force=='on')
90 print "Rendering file: "+filename+"\n"
91 queue_render(db,filename)
93 minlat,minlon,maxlat,maxlon=args
94 queue_tiles(db,float(minlat),float(minlon),float(maxlat),float(maxlon),int(zoom))
97 process_queue(db,map,force)
99 if __name__ == "__main__":