fix(raw_to_cog): 完善GDT_Byte类型无效值设置逻辑.

This commit is contained in:
谢泓 2026-01-28 19:49:42 +08:00
parent 4dd7077d56
commit c82b58e91d

View File

@ -8,7 +8,7 @@ COG (Cloud Optimized GeoTIFF) 是一种优化设计的 GeoTIFF 文件格式, 特
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Authors: CVEO Team Authors: CVEO Team
Last Updated: 2026-01-08 Last Updated: 2026-01-28
=============================================================================== ===============================================================================
""" """
@ -76,6 +76,8 @@ def tif_to_cog(
no_data = -32768 no_data = -32768
elif output_type == gdal.GDT_Float32: elif output_type == gdal.GDT_Float32:
no_data = -9999 no_data = -9999
elif output_type == gdal.GDT_Byte:
no_data = None
else: else:
no_data = np.nan no_data = np.nan
logging.warning(f"原数据未设无效值, 现已设为: {no_data}") 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 input_path = input_dir / file_name
output_path = output_dir / file_name output_path = output_dir / file_name
# 关于无效值 # 关于无效值
# Float32 类型可以设为 -9999; 8bit 类型可以设为 0 # Float32 类型可以设为 -9999
tif_to_cog(str(input_path), str(output_path), output_type, no_data=-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__": if __name__ == "__main__":