if __name__=='__main__': oldlzts = 36 for zoom in [2,3]: oldtilesize = getTileSize(zoom, lzts=oldlzts) newtilesize = getTileSize(zoom, lzts=oldlzts/2) try: os.mkdir('n/' + str(zoom)) except: pass for dir in os.walk(str(zoom)): print 'processing', dir[0] for file in dir[2]: try: row, col = int(file.split('_')[0]), int(file.split('_')[1].split('x')[0]) except: continue b = _get_tile_bbox(col, row, oldtilesize) t = {} t[0] = b.north, b.west t[1] = b.north, b.west + (b.west - b.east) / 2 t[2] = b.north - abs(b.north - b.south) / 2, b.west t[3] = b.north - abs(b.north - b.south) / 2, b.west + abs(b.west - b.east) / 2 for i in [0, 1, 2, 3]: t_row = getRowFromLat(t[i][0], newtilesize) t_col = getColFromLng(t[i][1], newtilesize) try: os.mkdir('n/%i/%i' % (zoom, t_row)) except: pass src = '%i/%04.i/%04.i_%04.ix%i.jpg' % (zoom, row, row, col, i) dst = 'n/%i/%i/%i_%i.jpg' % (zoom, t_row, t_row, t_col) copy(src, dst)