[FWTools] Python "batch" processing

Matt Wilkie matt.wilkie at gov.yk.ca
Tue Mar 2 13:33:49 EST 2010


> I make a .bat file with these lines and it will run the first line if
>  it's pct2rgb, it takes about 20 sec.  If the first line is 
> gdal_translate, which  is very fast, then the following pct2rgb line
> will run.  That's all, no more lines are processed.

When running a batch file from within a batch file you need to use the 
CALL statement else control is passed to the second file and does not 
return. See http://ss64.com/nt/call.html for more info. Pct2rgb is 
actually a batch wrapper around a python script. The same goes for the 
utilities at http://www.gdal.org/gdal_utilities.html which end in .py.

---------
@echo off
:: convert to rgb and clip several images
call pct2rgb "Alaska\Dutch Harbor 42 North.tif"  Work\AK\DutchN.tif
gdal_translate ...etc
call pctrgb ..etc
---------

Additionally, you may find this useful:
------
for %%f in (Alaska\*.tif) do (
    call pct2rgb "%%f" "work\AK\%%~nxf"
    )
-----
    http://ss64.com/nt/for2.html
    http://ss64.com/nt/syntax-args.html

cheers,

matt wilkie
--------------------------------------------
Geomatics Analyst
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/
--------------------------------------------


nlneilson wrote:
> My email shows there were two response Matt Wilkie, Roger André But 
> this thread is not updated, maybe I am doing something wrong.
> 
> What I am trying to do is batch process 100 + files:
> 
> pct2rgb "Alaska\Dutch Harbor 42 North.tif"  Work\AK\DutchN.tif 
> gdal_translate -srcwin 0 360 10950 3700 "Alaska\Dutch Harbor 42 
> South.tif" Work\Ak\DutchSc.tif pct2rgb Work\Ak\DutchSc.tif 
> Work\AK\DutchS.tif pct2rgb "Alaska\Fairbanks 85 North.tif" 
> Work\AK\FairbN.tif
> 
> Some need to be clipped with gdal_translate, this set has about 6, 
> another set has about 75. Then pct2rgb
> 
> I did this several times before one at a time.
> 
> I have a Python app and all of the lines print correctly.  Each of 
> the lines pasted at the fwtools prompt work OK.  When I run the .py 
> app at the prompt the lines print correctly but it doesn't do 
> anything.
> 

> 
> I thought it may be easier to try a time delay in the .py app.
> 
> It may be something basic I am doing wrong with the .py or .bat.
> 
> 
> 
> nlneilson wrote:
>> I did a search for "batch" but did not find a direct answer 
>> regarding Python.
>> 
>> Can a Python .py app batch process files the same as with a .bat 
>> batch file?
>> 
>> I could have a .py app make a .bat file but I was wondering if a 
>> .py app could do this directly??
>> 
> 


More information about the FWTools mailing list