1

How can I generate the Erdas batch list file (.blf) using Python? For example, I want to run a 5x5 median filter in the Batch Command Editor using a subset of images within a folder. Erdas provides a way to load lists of files, although I am not sure how to generate these outside of Erdas.

enter image description here

1 Answer 1

2

.bls files are relatively easy to create. It's the .bcf files that are very difficult to create in python because ERDAS has horrible batch creation and debugging. I've done both in Python before, and here is an excerpt from the .bls creation. It's from ERDAS 2011, though I think it still works with 2013.....

md = <folder>

images = arcpy.ListRasters()        
inputs = open(os.path.join(md, "List.bls"), "w")
inputs.write("Input\n")

arcpy.SetProgressor("step", "Processing....", 0, len(images)-1, 1)   
for i,img in enumerate(images):          
     arcpy.SetProgressorPosition(i)      
     inputs.write("{0}/{1}\n".format(directory, img))

inputs.close()

It's been a while since I messed with waterbody extraction, so this is kind of a mess. I do remember ERDAS hated backslashes in pathnames, so I forced /.

Here's the .bcf:

bcf = open(md + "Batch.bcf", "w")
bcf.write("""variable Input User;
variable recode Auto "$(Input.path)Output/Rasters/Temp/$(Input.root)";
variable rt Auto "$(Input.path)Output/Rasters/Recode/$(Input.name)";
variable ct Auto "$(Input.path)Output/Rasters/Clump/$(Input.name)";
variable et Auto "$(Input.path)Output/Rasters/Eliminate/$(Input.name)";
variable Output Auto "$(Input.path)Output/Shapefiles/Vectors/$(Input.name)";
modeler -nq recode.pmdl -meter -state "$(Input)" "$(rt)" 'Unsigned 8 bit' ignore "None" "$(recode)" 1 'Thematic bin direct default' "Thematic" "Thematic"
modeler -nq $IMAGINE_HOME/etc/models/clump.pmdl -meter -state "$(rt)" 1 "$(ct)" 0 0 '$(rt.FileRight)' '$(rt.FileBottom)' File ignore "None" 8
modeler -nq $IMAGINE_HOME/etc/models/eliminate.pmdl -meter -state "$(ct)" 1 "$(et)" 'Unsigned 8 bit' 0 0 '$(ct.FileRight)' '$(ct.FileBottom)' File ignore "None" 10 "pixels"
rastertoshape -in '$(et)' -out '$(Output)' -window 0 0 '$(et.FileRight)' '$(et.FileBottom)' File -aoi None -meter -neighbor 8""")

For whatever reason, ERDAS sometimes wanted double quotes and sometimes single quotes. It made debugging and writing very frustrating. Like I mentioned, this probably won't even work in the newer versions of Imagine.

I used the path and name from the .bls to build the variables that would be used as IO between the different tools. With python, it was straightforward enough to create all the folders needed.

2
  • This is really helpful, thanks. Do you know if it is required to have an input and output in the .bls file? This gets me the formatting that is apparently needed (ftp.ecn.purdue.edu/jshan/86/help/html/session/batch_wizard.htm), although it doe not seem to work in Erdas.
    – Aaron
    Commented Jul 12, 2014 at 21:05
  • @Aaron, I never stuck outputs in the .bls. I was able to hack together a solution in the .bcf. I edited my post to show this.
    – Paul
    Commented Jul 12, 2014 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.