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 # определяем примерный стартовый зум
23 minlatrad = math.radians(minlat)
24 maxlatrad = math.radians(maxlat)
26 minx = (minlon + 180.0)/360.0
27 maxx = (maxlon + 180.0)/360.0
29 miny = (1.0 - math.log(math.tan(minlatrad) + (1 / math.cos(minlatrad))) / math.pi) / 2.0
30 maxy = (1.0 - math.log(math.tan(maxlatrad) + (1 / math.cos(maxlatrad))) / math.pi) / 2.0
40 maxzoom=forced_max_zoom
44 for zoom in range(minzoom,maxzoom+1):
54 print zoom,minxt,maxxt,minyt,maxyt
55 ins.execute('insert into render_queue(zoom,minx,maxx,miny,maxy) values(?,?,?,?,?)',(zoom,minxt,maxxt,minyt,maxyt))
57 if forced_max_zoom is None:
58 if (maxxt-minxt>32) or (maxyt-minyt>24):
65 def process_queue(db,map,force=False):
69 conn = sqlite3.connect(db)
71 cur.execute('select id,zoom,minx,maxx,miny,maxy from render_queue')
76 id,zoom,minx,maxx,miny,maxy=rec
78 command = 'map='+map+ \
80 ' x='+str(minx)+'-'+str(maxx)+ \
81 ' y='+str(miny)+'-'+str(maxy)
84 command = 'tirex-batch '+command
86 command = 'tirex-batch '+command+' -f not-exists'
90 if system(command)==0:
92 dcur.execute('delete from render_queue where id=?',(id,))
97 from optparse import OptionParser
99 parser = OptionParser()
100 parser.add_option("-d", "--data", dest="directory",
101 help="Data directory", metavar="DIR")
102 parser.add_option("-m", "--map", dest="map",
103 help="Map name", metavar="MAP")
104 parser.add_option("-z", "--zoom", dest="zoom",
105 help="Maximal zoom (forced), used with coordinates pairs (minlat minlon maxlat maxlon) or filename in arguments", metavar="MAP")
106 parser.add_option("-f", "--force", dest="force",
107 help="Force tile regeneration (on/off), default off")
108 (options, args) = parser.parse_args()
112 db=options.directory+'/gpx.db'
115 force=(options.force=='on')
120 print "Rendering file: "+filename+"\n"
121 queue_render(db,filename)
123 minlat,minlon,maxlat,maxlon=args
124 queue_tiles(db,float(minlat),float(minlon),float(maxlat),float(maxlon),int(zoom))
127 process_queue(db,map,force)
129 if __name__ == "__main__":