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'),))
14 minlat,minlon,maxlat,maxlon=cur.fetchone()
15 queue_tiles(db,minlat,minlon,maxlat,maxlon)
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 not forced_max_zoom:
58 if (maxxt-minxt>16) or (maxyt-minyt>12):
64 def process_queue(db,map):
68 conn = sqlite3.connect(db)
70 cur.execute('select id,zoom,minx,maxx,miny,maxy from render_queue')
75 id,zoom,minx,maxx,miny,maxy=rec
77 command = 'render_list -a -m '+map+ \
78 ' -z '+str(zoom)+' -Z '+str(zoom)+ \
79 ' -x '+str(minx)+' -X '+str(maxx)+ \
80 ' -y '+str(miny)+' -Y '+str(maxy)
81 if system(command)==0:
83 dcur.execute('delete from render_queue where id=?',(id,))
88 from optparse import OptionParser
90 parser = OptionParser()
91 parser.add_option("-d", "--data", dest="directory",
92 help="Data directory", metavar="DIR")
93 parser.add_option("-m", "--map", dest="map",
94 help="Map name", metavar="MAP")
95 parser.add_option("-z", "--zoom", dest="zoom",
96 help="Maximal zoom (forced), used with coordinates pairs (minlat minlon maxlat maxlon) in arguments", metavar="MAP")
97 (options, args) = parser.parse_args()
99 db=options.directory+'/gpx.db'
104 minlat,minlon,maxlat,maxlon=args
105 queue_tiles(db,float(minlat),float(minlon),float(maxlat),float(maxlon),int(zoom))
108 process_queue(db,map)
110 if __name__ == "__main__":