From a846232e04b67285e1d1bfe7730e8b14f71f64f9 Mon Sep 17 00:00:00 2001 From: xhong Date: Thu, 8 Jan 2026 12:02:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(raw=5Fto=5Fcog):=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=E5=B0=9D=E8=AF=95=E6=9B=BF=E6=8D=A2=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E5=B9=B6=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/raw_to_cog.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/raw_to_cog.py b/utils/raw_to_cog.py index d65f17a..d97a5e6 100644 --- a/utils/raw_to_cog.py +++ b/utils/raw_to_cog.py @@ -56,7 +56,9 @@ def tif_to_cog( 压缩算法, 可选 "DEFLATE" 或 "LZW", by default "DEFLATE" """ logging.info(f"输入文件: {input_path}") - ds = gdal.Open(str(input_path)) + if not os.path.exists(str(input_path)): + input_path = str(input_path).replace(".tif", "(2).tif") + ds = gdal.Open(input_path) if ds is None: logging.error(f"无法打开输入文件: {input_path}") return @@ -98,7 +100,7 @@ def tif_to_cog( return -def main(input_dir, file_name, output_path): +def main(input_dir, file_name, output_path, output_type=gdal.GDT_Float32): input_dir = Path(input_dir) output_dir = Path(output_path) os.makedirs(output_dir, exist_ok=True) @@ -109,7 +111,7 @@ def main(input_dir, file_name, output_path): output_path = output_dir / file_name # 关于无效值 # Float32 类型可以设为 -9999; 8bit 类型可以设为 0 - tif_to_cog(str(input_path), str(output_path), no_data=-9999) + tif_to_cog(str(input_path), str(output_path), output_type, no_data=-9999) if __name__ == "__main__":