From 9ad27ac6d4ca922c2fa30481f1124e701ea03f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 26 Sep 2025 10:03:05 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E6=89=B9=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LabelPortShipRasterSlice/shpfile2dotaBatch.py | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 LabelPortShipRasterSlice/shpfile2dotaBatch.py diff --git a/LabelPortShipRasterSlice/shpfile2dotaBatch.py b/LabelPortShipRasterSlice/shpfile2dotaBatch.py new file mode 100644 index 0000000..5549614 --- /dev/null +++ b/LabelPortShipRasterSlice/shpfile2dotaBatch.py @@ -0,0 +1,79 @@ +import numpy as np +import os +from glob import glob +from pathlib import Path +# from multiprocessing import Pool +######################################################## +# 函数区 +######################################################## + +spacetySliceEnvPathExEPath=r"D:\ProgramData\miniconda3\envs\spacetySliceEnv\python.exe" + +def find_tif_files_pathlib(directory): + """ + 使用pathlib.Path.rglob递归查找指定目录下所有.tif和.tiff文件 + + 参数: + directory (str): 要搜索的根目录路径 + + 返回: + list: 包含所有找到的.tif/.tiff文件完整路径的列表 + """ + path = Path(directory) + # 使用rglob递归匹配所有.tif和.tiff文件 + tif_files = list(path.rglob('*.tif')) + list(path.rglob('*.tiff')) + # 将Path对象转换为字符串路径 + return [str(file) for file in tif_files] + + +def find_shp_files_pathlib(directory): + """ + 使用pathlib.Path.rglob递归查找指定目录下所有.tif和.tiff文件 + + 参数: + directory (str): 要搜索的根目录路径 + + 返回: + list: 包含所有找到的.tif/.tiff文件完整路径的列表 + """ + path = Path(directory) + # 使用rglob递归匹配所有.tif和.tiff文件 + tif_files = list(path.rglob('*.shp')) + # 将Path对象转换为字符串路径 + return [str(file) for file in tif_files] + + +def preProcessLabelshapefile(shpfilepath,preFolderPath): + if not os.path.exists(preFolderPath): + os.makedirs(preFolderPath) + file_path = Path(shpfilepath) + directory_path = str(file_path.resolve().parent.name) + + rootname = Path(shpfilepath).stem + txtpath=os.path.join(preFolderPath,rootname+'.txt') + programpath=r"R:\TYSAR-德清院\A-预处理-未标注\A0-算法版本\AA\SpacetySliceDataTools\LabelPortShipRasterSlice\Portshapefile2dota_AA.py" + cmdtxt=r"{} {} -i {} -o {}".format(spacetySliceEnvPathExEPath,programpath,shpfilepath,txtpath) + if os.system(cmdtxt) ==2: + print("sucess:",cmdtxt) + return "sucess: {}".format(cmdtxt) + else: + print("failed:",cmdtxt) + return "failed: {}".format(cmdtxt) + pass + + +######################################################## +# 流程执行区 +######################################################## +if __name__ == '__main__': + srcFolderPath = r"D:\Annotation_Y\港口\聚束模式" + preFolderPath= r"D:\Annotation_Y\港口\聚束模式" + shpPaths = find_shp_files_pathlib(srcFolderPath) + for shppath in shpPaths: + preProcessLabelshapefile(shppath, preFolderPath) + + + + + +