main.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from file_util import *
  2. from db_util import getDiffEwkt
  3. from img_util import savePng
  4. from img_util import saveImage
  5. from img_util import getImageSize
  6. import re
  7. # 1.获取图斑的根目录
  8. dirs = getDirList('img', '2024')
  9. for dir in dirs:
  10. # 2.获取tif路径
  11. allPathList = getAllFiles(dir+'/DDOM')
  12. for filePath in allPathList:
  13. print('tif路径:'+filePath)
  14. imageSize=getImageSize(filePath)
  15. if not(imageSize[0] ==256 and imageSize[1] == 256):
  16. print('图片尺寸不是256:',imageSize)
  17. continue
  18. # 3.获取tif的边界矢量范围
  19. ewkt = getTifEwkt(filePath)
  20. # 4.tif边界-变化矢量(生成图片的黑色部分)
  21. match = re.search(r'/DDOM/(.*)DDOM\.tif', filePath)
  22. code = match.group(1) if match else ''
  23. tbName=dir.replace('img/','')
  24. ewkt = getDiffEwkt(ewkt, tbName)
  25. # 5.生成变化的图片
  26. savePng(code, ewkt, 'img/lable')
  27. # 6.tif转png
  28. saveImage(filePath,'img/A/'+code+'.tif')
  29. filePath=filePath.replace('DDOM','QDOM')
  30. saveImage(filePath,'img/B/'+code+'.tif')