from file_util import * from db_util import getDiffEwkt from img_util import savePng from img_util import saveImage from img_util import getImageSize import re # 1.获取图斑的根目录 dirs = getDirList('img', '2024') for dir in dirs: # 2.获取tif路径 allPathList = getAllFiles(dir+'/DDOM') for filePath in allPathList: print('tif路径:'+filePath) imageSize=getImageSize(filePath) if not(imageSize[0] ==256 and imageSize[1] == 256): print('图片尺寸不是256:',imageSize) continue # 3.获取tif的边界矢量范围 ewkt = getTifEwkt(filePath) # 4.tif边界-变化矢量(生成图片的黑色部分) match = re.search(r'/DDOM/(.*)DDOM\.tif', filePath) code = match.group(1) if match else '' tbName=dir.replace('img/','') ewkt = getDiffEwkt(ewkt, tbName) # 5.生成变化的图片 savePng(code, ewkt, 'img/lable') # 6.tif转png saveImage(filePath,'img/A/'+code+'.tif') filePath=filePath.replace('DDOM','QDOM') saveImage(filePath,'img/B/'+code+'.tif')