Разложили файлы по годам и месяцам. Много накопилось.
[pyrungps.git] / render_tiles.py
old mode 100644 (file)
new mode 100755 (executable)
index e229ead..1116287
@@ -26,7 +26,7 @@ def queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom=None):
   conn = sqlite3.connect(db)
   
   # определяем примерный стартовый зум
-  
+
   minzoom=8
 
   if forced_max_zoom:
@@ -36,19 +36,23 @@ def queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom=None):
     while True:
       minx,miny=deg2num(minlat,minlon,maxzoom)
       maxx,maxy=deg2num(maxlat,maxlon,maxzoom)
+      
       print maxzoom,':',minx,'-',maxx,'/',miny,'-',maxy
       if (maxx-minx>16) or (maxy-miny>12) or (maxzoom==16):
         break
       else:
         maxzoom=maxzoom+1   
   
+  if maxzoom<minzoom:
+    minzoom=maxzoom
+  
   ins = conn.cursor()
-  print minlat,maxlat,minlon,maxlon,minzoom,maxzoom
+  print minlat,minlon,maxlat,maxlon,minzoom,maxzoom
   ins.execute('insert into render_queue(minlat,maxlat,minlon,maxlon,minzoom,maxzoom) values(?,?,?,?,?,?)',(minlat,maxlat,minlon,maxlon,minzoom,maxzoom))
 
   conn.commit()        
 
-def process_queue(db,map,force=False):
+def process_queue(db,map,force=False,backend="renderd"):
 
   from os import system
 
@@ -60,20 +64,62 @@ def process_queue(db,map,force=False):
   for rec in list:
   
     id,minlat,maxlat,minlon,maxlon,minzoom,maxzoom=rec
+    
+    if backend == "tirex" or backend == "default":    
+
+      command = 'map='+map+ \
+        ' z='+str(minzoom)+'-'+str(maxzoom)+ \
+        ' lat='+str(minlat)+','+str(maxlat)+ \
+        ' lon='+str(minlon)+','+str(maxlon)
+
+      if force:
+        command = 'tirex-batch -n 0 --prio=50 '+command
+      else:
+        command = 'tirex-batch -n 0 --prio=50 '+command+' -f not-exists'  
+
+      print command  
+      
+      if system(command)==0:
+        dcur=conn.cursor()
+        dcur.execute('delete from render_queue where id=?',(id,))
+        conn.commit()
 
-    command = 'map='+map+ \
-      ' z='+str(minzoom)+'-'+str(maxzoom)+ \
-      ' lat='+str(minlat)+','+str(maxlat)+ \
-      ' lon='+str(minlon)+','+str(maxlon)
+    elif backend == "renderd":
+    
+      print minlat,minlon,maxlat,maxlon
+    
+      for zoom in range(minzoom,maxzoom+1):
+        minx,miny=deg2num(minlat,minlon,zoom)
+        maxx,maxy=deg2num(maxlat,maxlon,zoom)
+
+        if minx>maxx:
+          tx=minx
+          maxx=minx
+          minx=tx
+
+        if miny>maxy:
+          ty=miny
+          maxy=miny
+          miny=ty
+
+        print zoom,minx,miny,maxx,maxy
 
-    if force:
-      command = 'tirex-batch -n 0 '+command
-    else:
-      command = 'tirex-batch -n 0 '+command+' -f not-exists'  
+        maps = map.split(',')
+        
+        for map_name in maps:
+
+          command = 'render_list -a -m '+map+ \
+                    ' -z '+str(zoom)+' -Z '+str(zoom)+ \
+                    ' -x '+str(minx)+' -X '+str(maxx)+ \
+                    ' -y '+str(miny)+' -Y '+str(maxy)
+          if force:
+            command = command+ ' --force'
     
-    print command  
+          print command  
       
-    if system(command)==0:
+          if system(command)<>0:
+            return
+
       dcur=conn.cursor()
       dcur.execute('delete from render_queue where id=?',(id,))
       conn.commit()
@@ -91,10 +137,10 @@ def main():
     help="Maximal zoom (forced), used with coordinates pairs (minlat minlon maxlat maxlon) or filename in arguments", metavar="MAP")
   parser.add_option("-f", "--force", dest="force", 
     help="Force tile regeneration (on/off), default off")
+  parser.add_option("-r", "--renderer", dest="renderer", 
+    help="Rendering backend: tirex or renderd")
   (options, args) = parser.parse_args()  
 
-  print options,args
-
   db=options.directory+'/gpx.db'
   map=options.map  
   zoom=options.zoom
@@ -102,6 +148,12 @@ def main():
     zoom=12
   force=(options.force=='on')
 
+  if options.renderer:
+    renderer=options.renderer
+  else:
+    print "Using default rendering backend..."
+    renderer="default"
+
   if len(args)==1:
     filename,=args
     print "Rendering file: "+filename+"\n"
@@ -112,8 +164,8 @@ def main():
     queue_tiles(db,float(minlat),float(minlon),float(maxlat),float(maxlon),int(zoom))
 
   if map:
-    print "Processing map "+map+"\n"
-    process_queue(db,map,force)
+    print "Processing map(s) "+map+"\n"
+    process_queue(db,map,force,renderer)
   
 if __name__ == "__main__":