import os import rasterio from shapely.geometry import box def getAllFiles(filePath): fileList = [] # 设置要遍历的文件夹路径 folder_path = os.path.join(os.path.dirname(__file__), filePath) # 遍历文件夹 for root, dirs, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) if file_path.endswith('.tif') or file_path.endswith('.TIF'): fileList.append(file_path) return fileList # 获取当前目录下的文件夹 def getDirList(filePath,startName): dirList = [] # 设置要遍历的文件夹路径 folder_path = os.path.join(os.path.dirname(__file__), filePath) # 遍历文件夹 for root, dirs, files in os.walk(folder_path): for dir in dirs: if dir.startswith(startName): dirList.append(filePath+'/'+dir) return dirList # getDirList('img') def getTifEwkt(filePath): # 读取 tif 文件 with rasterio.open(filePath) as src: # 获取 tif 文件的边界框 (bounds) bounds = src.bounds # 使用 shapely 的 box 函数创建矩形几何对象 bbox = box(bounds.left, bounds.bottom, bounds.right, bounds.top) # 将矩形几何对象转换为 WKT 格式 wkt = bbox.wkt ewkt='SRID=4490;'+wkt print('矢量范围:'+wkt) return ewkt