file_util.py 929 B

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import rasterio
  3. from shapely.geometry import box
  4. def getAllFiles(filePath):
  5. fileList = []
  6. # 设置要遍历的文件夹路径
  7. folder_path = os.path.join(os.path.dirname(__file__), filePath)
  8. # 遍历文件夹
  9. for root, dirs, files in os.walk(folder_path):
  10. for file in files:
  11. file_path = os.path.join(root, file)
  12. fileList.append(file_path)
  13. return fileList
  14. # allPath = getAllFiles('img/DDOM')
  15. def getTifEwkt(filePath):
  16. # 读取 tif 文件
  17. with rasterio.open(filePath) as src:
  18. # 获取 tif 文件的边界框 (bounds)
  19. bounds = src.bounds
  20. # 使用 shapely 的 box 函数创建矩形几何对象
  21. bbox = box(bounds.left, bounds.bottom, bounds.right, bounds.top)
  22. # 将矩形几何对象转换为 WKT 格式
  23. wkt = bbox.wkt
  24. ewkt='SRID=4490;'+wkt
  25. print('矢量范围:'+wkt)
  26. return ewkt