1.为什么要编写此脚本
由于自带的tilecache_seed.py出现问题,运行就报错误,结合它的Client.py及Service.py和Layer.py的代码,编写了一个简单的脚本,用来实现tilecache_seed.py的功能。
2.脚本代码如下:
#!/usr/bin/python
"""
引入服务类
"""
import TileCache.Service
import time,math,sys
"""
从tilecache的layer包引入tile类
"""
from TileCache.Layer import Tile
cfgfile=sys.argv[1]
layername=sys.argv[2]
zoom=sys.argv[3]
zooms=zoom.split(",")
if len(sys.argv) == 4:
s=TileCache.Service.load(cfgfile)
basic=s.layers[layername]
for z in range(int(zooms[0]),int(zooms[1]),1):
bottomleft=basic.getClosestCell(z,basic.bbox[0:2])
topright=basic.getClosestCell(z,basic.bbox[2:4])
print 'bottomleft='+str(bottomleft)+"\n\ttopright="+str(topright)
zcount=0
metaSize=basic.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(basic,x,y,z)
s.renderTile(tile)
zcount+=1
print '\n\tx='+str(x)+'\n\ty='+str(y)+'\n\tz='+str(z)+'run time='+str((time.time()-tileStart))
else:
print 'please input arguments examples:\n\tpython client_seed.py /etc/tilecache.cfg basic 5,6\n\tthis is seed 5 to 6 photo!\n\t'
if __name__ == '__main__':
main()
3.运行此脚本:
python client_seed.py /etc/tilecache.cfg basic 5,6