[Tilecache] Patch for tilecache_seed

Bruce Rindahl rindahl at lrcwe.com
Tue Dec 23 12:10:54 EST 2008


Attached is a patch against Client.py that allows a new parameter -r (or 
--reverse) to force tilecache_seed to create the tiles in reverse 
order.  Many times when seeding a cache something can cause a seeding 
operation to fail.  Restarting can take a long time to recheck if a tile 
is cached especially if you are dealing with thousands of tiles.  This 
can speed up the process - run it first in the forward direction, then 
in reverse.
Thanks!
Bruce

-------------- next part --------------
--- TileCache\Client.py	Tue Dec 16 10:22:16 2008
+++ \projects\Web\tilecache\TileCache\Client.py	Tue Dec 23 10:00:40 2008
@@ -73,7 +73,7 @@
     def setBBox (self, box):
         self.params["bbox"] = ",".join(map(str, box))
 
-def seed (svc, layer, levels = (0, 5), bbox = None, padding = 0, force = False ):
+def seed (svc, layer, levels = (0, 5), bbox = None, padding = 0, force = False, reverse = False ):
     from Layer import Tile
     try:
         padding = int(padding)
@@ -88,12 +88,29 @@
     for z in range(*levels):
         bottomleft = layer.getClosestCell(z, bbox[0:2])
         topright   = layer.getClosestCell(z, bbox[2:4])
-        print >>sys.stderr, "###### %s, %s" % (bottomleft, topright)
+        # Why Are we printing to sys.stderr??? It's not an error.
+        # This causes a termination if run from cron or in background if shell is terminated
+        #print >>sys.stderr, "###### %s, %s" % (bottomleft, topright)
+        print "###### %s, %s" % (bottomleft, topright)
         zcount = 0 
         metaSize = layer.getMetaSize(z)
-        ztiles = int(math.ceil(float(topright[1] - bottomleft[1]) / metaSize[0]) * math.ceil(float(topright[0] - bottomleft[0]) / metaSize[1])) 
-        for y in range(bottomleft[1] - (1 * padding), topright[1] + metaSize[1] + (1 * padding), metaSize[1]):
-            for x in range(bottomleft[0] - (1 * padding), topright[0] + metaSize[0] + (1 * padding), metaSize[0]):
+        ztiles = int(math.ceil(float(topright[1] - bottomleft[1]) / metaSize[0]) * math.ceil(float(topright[0] - bottomleft[0]) / metaSize[1]))
+        if reverse:
+            startX = topright[0] + metaSize[0] + (1 * padding)
+            endX = bottomleft[0] - (1 * padding)
+            stepX = -metaSize[0]
+            startY = topright[1] + metaSize[1] + (1 * padding)
+            endY = bottomleft[1] - (1 * padding)
+            stepY = -metaSize[1]
+        else:
+            startX = bottomleft[0] - (1 * padding)
+            endX = topright[0] + metaSize[0] + (1 * padding)
+            stepX = metaSize[0]
+            startY = bottomleft[1] - (1 * padding)
+            endY = topright[1] + metaSize[1] + (1 * padding)
+            stepY = metaSize[1]
+        for y in range(startY, endY, stepY):
+            for x in range(startX, endX, stepX):
                 tileStart = time.time()
                 tile = Tile(layer,x,y,z)
                 bounds = tile.bounds()
@@ -120,6 +137,9 @@
     parser.add_option("-p","--pading",action="store", type="int", dest="padding", default = 0,
                       help="extra margin tiles to seed around target area")
    
+    parser.add_option("-r","--reverse", action="store_true", dest="reverse", default = False,
+                      help="Reverse order of seeding tiles")
+    
     (options, args) = parser.parse_args()
     
     from Service import Service, cfgfiles
@@ -134,7 +154,7 @@
     
         
     if len(args)>1:    
-        seed(svc, layer, map(int, args[1:3]), bboxlist , padding=options.padding, force = options.force)
+        seed(svc, layer, map(int, args[1:3]), bboxlist , padding=options.padding, force = options.force, reverse = options.reverse)
     else:
         for line in sys.stdin.readlines():
             lat, lon, delta = map(float, line.split(","))


More information about the Tilecache mailing list