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', '2023_1023') for dir in dirs: print('图斑根目录:'+dir) # 2.获取tif路径 allPathList = getAllFiles(dir+'/QDOM') print('tif路径长度:'+allPathList.__len__().__str__()) for filePath in allPathList: print('tif路径:'+filePath) imageSize=getImageSize(filePath) size0=imageSize[0] size1=imageSize[1] # if not(imageSize[0] ==256 and imageSize[1] == 256): # print('图片尺寸不是256:',imageSize) # continue # 3.获取tif的边界矢量范围 ewkt = getTifEwkt(filePath) # 4.tif边界-变化矢量(生成图片的黑色部分) fileType=filePath.split('.')[-1] match = re.search(r'/QDOM/(.*)\.'+fileType, filePath) code = match.group(1) if match else '' tbName=dir.replace('img/','') ewkt = getDiffEwkt(ewkt, tbName) # 5.生成变化的图片 savePng(code, ewkt, 'img/lable',size0,size1) # 6.tif转png saveImage(filePath,'img/A/'+code+'.'+fileType) filePath=filePath.replace('/QDOM/','/DDOM_QDOM_crop1/') filePath=filePath.replace('QDOM.','DDOM.') saveImage(filePath,'img/B/'+code+'.'+fileType) print('end')