Esempio n. 1
0
def fetch_tile_range(thread_no, svc, layer, startX, endX, stepX, startY, endY, stepY, z, total, zcount, start, force=False, reverse=False, delay=0):
    from Layer import Tile
    print "Generating tiles from (", startX, ",", startY, ") to (", endX, ",", endY, ")"

    # Local count
    total_tiles = (endY - startY) * (endX - startX)

    for y in range(startY, endY, stepY):
        for x in range(startX, endX, stepX):
            try:
                tileStart = time.time()
                tile = Tile(layer,x,y,z)
                bounds = tile.bounds()
                svc.renderTile(tile,force=force)
                total += 1
                zcount += 1
                box = "(%.4f %.4f %.4f %.4f)" % bounds
                print "[Thread %s] %01d (%06d, %06d) = %s [%.4fs : %.3f/s] %s/%s" \
                     % (thread_no, z,x,y, box, time.time() - tileStart, total / (time.time() - start + .0001), zcount, total_tiles)
                if delay:
                    time.sleep(delay)
            except KeyboardInterrupt, k:
                return
            except Exception, e:
                print >> sys.stderr, "Thread [%s]" % thread_no
                print >> sys.stderr, e
                print >> sys.stderr, "(%s, %s, %s) %s/%s" % (x, y, z, zcount, total_tiles)
Esempio n. 2
0
def seed(svc, base, layer, levels=(0, 5), bbox=None):
    from Layer import Tile

    if not bbox: bbox = layer.bbox

    start = time.time()
    total = 0

    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)
        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], topright[1], metaSize[1]):
            for x in range(bottomleft[0], topright[0], metaSize[0]):
                tileStart = time.time()
                tile = Tile(layer, x, y, z)
                bounds = tile.bounds()
                svc.renderTile(tile)
                total += 1
                zcount += 1
                box = "(%.4f %.4f %.4f %.4f)" % bounds
                print "%02d (%06d, %06d) = %s [%.4fs : %.3f/s] %s/%s" \
                     % (z,x,y, box, time.time() - tileStart, total / (time.time() - start + .0001), zcount, ztiles)
Esempio n. 3
0
def seed(svc,
         layer,
         levels=(0, 5),
         bbox=None,
         padding=0,
         force=False,
         reverse=False,
         delay=0):
    from Layer import Tile
    try:
        padding = int(padding)
    except:
        raise Exception(
            'Your padding parameter is %s, but should be an integer' % padding)

    if not bbox: bbox = layer.bbox

    start = time.time()
    total = 0

    for z in range(*levels):
        bottomleft = layer.getClosestCell(z, bbox[0:2])
        topright = layer.getClosestCell(z, bbox[2:4])
        # 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]))
        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()
                svc.renderTile(tile, force=force)
                total += 1
                zcount += 1
                box = "(%.4f %.4f %.4f %.4f)" % bounds
                print "%02d (%06d, %06d) = %s [%.4fs : %.3f/s] %s/%s" \
                     % (z,x,y, box, time.time() - tileStart, total / (time.time() - start + .0001), zcount, ztiles)
                if delay:
                    time.sleep(delay)
Esempio n. 4
0
def seed (svc, layer, levels = (0, 5), bbox = None, padding = 0, force = False, reverse = False, delay = 0 ):
    from Layer import Tile
    try:
        padding = int(padding)
    except:
        raise Exception('Your padding parameter is %s, but should be an integer' % padding)

    if not bbox: bbox = layer.bbox

    start = time.time()
    total = 0
    
    for z in range(*levels):
	sys.stdout.write ("z:"+str(z))
        bottomleft = layer.getClosestCell(z, bbox[0:2])
        topright   = layer.getClosestCell(z, bbox[2:4])
        # 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)
	zTileDim = 2**z
        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]

	if  endX >= zTileDim:
	    endX = endX - stepX
	if  endY >= zTileDim:
	    endY = endY - stepX

        for y in range(int(startY), int(endY), stepY):
            for x in range(int(startX), int(endX), stepX):
                tileStart = time.time()
                tile = Tile(layer,x,y,z)
                bounds = tile.bounds()
                svc.renderTile(tile,force=force)
                total += 1
                zcount += 1
                box = "(%.4f %.4f %.4f %.4f)" % bounds
                print "%02d (%06d, %06d) = %s [%.4fs : %.3f/s] %s/%s" \
                     % (z,x,y, box, time.time() - tileStart, total / (time.time() - start + .0001), zcount, ztiles)
                if delay:
                    time.sleep(delay)
def seed (layer, levels = (0, 5), bbox = None, zone = "", path_to_tiles= "", delete = False):
    from Layer import Tile

    if not bbox: bbox = layer.bbox

    geom_filter = loads(zone)

    for z in range(*levels):
        bottomleft = layer.getClosestCell(z, bbox[0:2])
        topright   = layer.getClosestCell(z, bbox[2:4])

        print "###### %s, %s" % (bottomleft, topright)
        zcount = 0 
        metaSize = (1,1)
        ztiles = int(math.ceil(float(topright[1] - bottomleft[1]) / metaSize[0]) * math.ceil(float(topright[0] - bottomleft[0]) / metaSize[1]))
        
        startX = topright[0] + metaSize[0]
        endX = bottomleft[0]
        stepX = -metaSize[0]
        startY = topright[1] + metaSize[1]
        endY = bottomleft[1]
        stepY = -metaSize[1]
        
        for y in range(startY, endY, stepY):
            for x in range(startX, endX, stepX):
                tile = Tile(layer,x,y,z)
                bounds = tile.bounds()
    
                tile_wkt = "POLYGON ((%s %s, %s %s, %s %s, %s %s, %s %s))" % (bounds[0], bounds[1], bounds[0], bounds[3], bounds[2], bounds[3], bounds[2], bounds[1], bounds[0], bounds[1])
                tile_geom = loads(tile_wkt)
                intersect =  geom_filter.intersects(tile_geom)
                
                if not intersect:
                    # Then delete the tile
                    zcount += 1
                    file_to_del = "%s/%s/%d/%d/%d.%s" % (path_to_tiles,layer.name, z, x, y, layer.extension)
                    if not delete:
                        print "To be deleted : %s" % (file_to_del)
                    else :
                        try:
                            os.remove(file_to_del)
                            print "File deleted : %s" % (file_to_del)
                        except:
                            print "File not found : %s" % (file_to_del)
                            pass
Esempio n. 6
0
def seed(svc, base, layer, levels=(0, 5), bbox=None):
    from Layer import Tile

    if not bbox:
        bbox = layer.bbox

    start = time.time()
    total = 0

    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)
        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], topright[1], metaSize[1]):
            for x in range(bottomleft[0], topright[0], metaSize[0]):
                tileStart = time.time()
                tile = Tile(layer, x, y, z)
                bounds = tile.bounds()
                svc.renderTile(tile)
                total += 1
                zcount += 1
                box = "(%.4f %.4f %.4f %.4f)" % bounds
                print "%02d (%06d, %06d) = %s [%.4fs : %.3f/s] %s/%s" % (
                    z,
                    x,
                    y,
                    box,
                    time.time() - tileStart,
                    total / (time.time() - start + 0.0001),
                    zcount,
                    ztiles,
                )
Esempio n. 7
0
 def thaw_GET(self, msgtxt, layers):
     layername, level, row, col = struct.unpack(self.tilespec, msgtxt)
     self.tile = Tile(layers[layername], row, col, level)