Files
td_official/public/image/convert_tif.bat

56 lines
1.3 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
setlocal
REM 源文件
set SRC=odm_orthophoto.tif
REM 中间文件:去掩膜 + 保留 4 波段
set TMP1=tmp_nomask.tif
REM 中间文件gdalwarp 处理透明通道
set TMP2=tmp_nomask_alpha.tif
REM 最终输出文件(性能优化:缩放 + 压缩)
set FINAL=clean_no_mask_optimized.tif
REM 配置参数
REM -tr 0.25x 分辨率控制0.25 倍像素或者每个像素大小扩大4倍视你项目需要可调
REM -co 压缩参数LZW 是无损压缩方式TILED=YES 支持分块加载
REM -r average 使用平均值重采样可保持图像质量
echo [1/4] gdal_translate去除掩膜并保留RGBA四波段...
gdal_translate -b 1 -b 2 -b 3 -b 4 -mask none -co PHOTOMETRIC=RGB -co ALPHA=YES %SRC% %TMP1%
if errorlevel 1 (
echo ❌ gdal_translate 失败
exit /b 1
)
echo [2/4] gdalwarp强制生成 Alpha 通道...
gdalwarp -dstalpha %TMP1% %TMP2%
if errorlevel 1 (
echo ❌ gdalwarp 失败
exit /b 1
)
echo [3/4] gdalwarp降采样并启用压缩优化...
gdalwarp ^
-r average ^
-tr 2 2 ^
-co COMPRESS=LZW ^
-co TILED=YES ^
-co PHOTOMETRIC=RGB ^
-co ALPHA=YES ^
%TMP2% %FINAL%
if errorlevel 1 (
echo ❌ gdalwarp 压缩优化失败
exit /b 1
)
echo [4/4] 清理临时文件...
del %TMP1%
del %TMP2%
echo ✅ 完成!优化后的 GeoTIFF 已生成:%FINAL%
endlocal
pause