[Gdal-dev] Resampling With GDAL

Matt Wilkie matt.wilkie at gov.yk.ca
Fri Apr 20 13:41:14 EDT 2007


Hi Mike,

thanks for sharing the resample-by-stages technique. I've spruced up the 
batch file a bit. I initially tried to change the hardcoded intermediate 
sizes to use percentages instead of pixels but it turns out that while 
gdal_translate can do that, gdalwarp does not.  Anyway, here is my update:

===============================================================
NiceResample.cmd
===============================================================
@echo off
echo.
echo.   %~n0: resample an image nicely, slow but with good results
echo.
if [%2]==[] goto :Usage
if not exist "%1" goto :NoFile
rem if exist "%2" goto :OutExists
set inFile=%1
set outFile=%2

:: enables variable expansion inside FOR loop (!x! syntax)
:: requires Windows 2000 or newer
setlocal enabledelayedexpansion

:Main
	set tmpFile=%infile%
	:: resample from 900x900 pixels down to 128x128
	:: in 100px stages.
	for %%a in (900 800 700 600 500 400 300 200 128) do (
		gdalwarp -q -ts %%a %%a !tmpFile! xx_%%a_%inFile%
		set tmpFile=xx_%%a_%inFile%
		)
	:: "&& del" only deletes if previous command successful
	gdal_translate !tmpFile! %outFile% && del xx_*_%inFile%
	echo.
	echo   Finished writing 128x128px %outFile%
	goto :EOF

:NoFile
	echo *** Error: input %1 not found
	goto :EOF

:Usage
	echo.	Usage: %~n0 [input image] [output image]
	echo.
	echo   output overwritten if it exists
	goto :EOF
===============================================================


-- 
matt wilkie
--------------------------------------------
Geographic Information,
Information Management and Technology,
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------




More information about the Gdal-dev mailing list