fix(raw_to_cog): 处理输入文件不存在时尝试替换文件名并支持自定义输出数据类型.
This commit is contained in:
parent
ae1c441e9a
commit
a846232e04
@ -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__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user