From c82b58e91d95f8e51dda5ce40a1f685be59eb94c Mon Sep 17 00:00:00 2001 From: xhong Date: Wed, 28 Jan 2026 19:49:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(raw=5Fto=5Fcog):=20=E5=AE=8C=E5=96=84GDT=5F?= =?UTF-8?q?Byte=E7=B1=BB=E5=9E=8B=E6=97=A0=E6=95=88=E5=80=BC=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=80=BB=E8=BE=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/raw_to_cog.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/raw_to_cog.py b/utils/raw_to_cog.py index 2179f56..eaa133f 100644 --- a/utils/raw_to_cog.py +++ b/utils/raw_to_cog.py @@ -8,7 +8,7 @@ COG (Cloud Optimized GeoTIFF) 是一种优化设计的 GeoTIFF 文件格式, 特 ------------------------------------------------------------------------------- Authors: CVEO Team -Last Updated: 2026-01-08 +Last Updated: 2026-01-28 =============================================================================== """ @@ -76,6 +76,8 @@ def tif_to_cog( no_data = -32768 elif output_type == gdal.GDT_Float32: no_data = -9999 + elif output_type == gdal.GDT_Byte: + no_data = None else: no_data = np.nan logging.warning(f"原数据未设无效值, 现已设为: {no_data}") @@ -113,8 +115,12 @@ def main(input_dir, file_name, output_path, output_type=gdal.GDT_Float32): input_path = input_dir / file_name output_path = output_dir / file_name # 关于无效值 - # Float32 类型可以设为 -9999; 8bit 类型可以设为 0 - tif_to_cog(str(input_path), str(output_path), output_type, no_data=-9999) + # Float32 类型可以设为 -9999 + if output_type == gdal.GDT_Float32: + no_data = -9999 + else: + no_data = np.nan + tif_to_cog(str(input_path), str(output_path), output_type, no_data=no_data) if __name__ == "__main__":