如何使用 GDAL TRANSFER 转换文件文件夹?
How to convert a folder of files with GDAL TRANSFER?
我有大约 2000 张图像需要使用 GDAL
将一些参数从 TIF
转换为 JPG
。我需要使用 CMD
脚本来实现这一点。到目前为止,这是我的脚本:
set "SourceFolder=C:\Tif\newimages\"
set "DestinationFolder=C:\Tif\temp"
set "CreatedFolder="
if not exist "%DestinationFolder%\" (
md "%DestinationFolder%" 2>nul
if not exist "%DestinationFolder%\" (
echo Error: Failed to create folder "%DestinationFolder%"
goto EndBatch
)
set "CreatedFolder=1"
)
for %%N in (%SourceFolder%*.tif) DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%i %DestinationFolder%\%%i*jpg
:EndBatch
endlocal
pause
这会在 CMD
上产生以下错误消息:
ERROR 4: %i: No such file or directory
背景:
Windows环境(显然)
OSGeo4W 命令到 运行 脚本。
我正在寻找的是对我在脚本中做错了什么的解释以及使其正常运行的建议。
编辑:
我意识到 gdal
行末尾的命令应该是转换文件的源和目标。有什么办法解决这个问题,因为我只需要在最后定义目标文件夹。我让它作为一个无限循环工作,这当然不是最佳的,因为图像数量超过 2000。
仔细检查后发现,我为 %%N
设置了一个值,后来尝试使用 %%i
。此外,gdal
命令应该是这样的:
DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%N %DestinationFolder%\%%~nN.jpg
而不是:
DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%i %DestinationFolder%\%%i*jpg
我有大约 2000 张图像需要使用 GDAL
将一些参数从 TIF
转换为 JPG
。我需要使用 CMD
脚本来实现这一点。到目前为止,这是我的脚本:
set "SourceFolder=C:\Tif\newimages\"
set "DestinationFolder=C:\Tif\temp"
set "CreatedFolder="
if not exist "%DestinationFolder%\" (
md "%DestinationFolder%" 2>nul
if not exist "%DestinationFolder%\" (
echo Error: Failed to create folder "%DestinationFolder%"
goto EndBatch
)
set "CreatedFolder=1"
)
for %%N in (%SourceFolder%*.tif) DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%i %DestinationFolder%\%%i*jpg
:EndBatch
endlocal
pause
这会在 CMD
上产生以下错误消息:
ERROR 4: %i: No such file or directory
背景:
Windows环境(显然)
OSGeo4W 命令到 运行 脚本。
我正在寻找的是对我在脚本中做错了什么的解释以及使其正常运行的建议。
编辑:
我意识到 gdal
行末尾的命令应该是转换文件的源和目标。有什么办法解决这个问题,因为我只需要在最后定义目标文件夹。我让它作为一个无限循环工作,这当然不是最佳的,因为图像数量超过 2000。
仔细检查后发现,我为 %%N
设置了一个值,后来尝试使用 %%i
。此外,gdal
命令应该是这样的:
DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%N %DestinationFolder%\%%~nN.jpg
而不是:
DO gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 %%i %DestinationFolder%\%%i*jpg