I have a series of bandmath processes that need to be run via envi and that I am doing over and over again. I have no experience with IDL but am trying to automate using it. I want to be able to choose input files via dialog box, or even just be able to pass the result of a bandmath process to the next process. I am able to do this automation using python and arc but don't seem to get the correct results, hence IDL and ENVI.

IDL documentation seems to indicate that that in IDL the bands need to be in the same raster whereas in ENVI I never need to do that. Is this the case? Am I missing a step to get my code to work?

Barring specifics, are there better tutorials out there than what's available in the code documentation?

My code

; Start ENVI
e = ENVI()

; Open a data file
Raster1 = e.OpenRaster(File1)

; Determine an output file
OutFile1 = e.GetTemporaryFilename()

Raster2 = e.OpenRaster(File2)

Outfile2 = e.GetTemporaryFilename()
; Return a file ID
fid = ENVIRasterToFID(Raster1)

Outfile3 = e.GetTemporaryFilename()

; Add the first two bands
ENVI_File_Query, fid, DIMS=dims
ENVI_Doit, 'Math_Doit', $
  FID = [fid, fid], $
  DIMS = dims, $
  POS = [0,1], $
  EXP = 'b1 + b2', $
  OUT_NAME = Outfile3

  • what is the exact error/problem you get, with the code above ?
    – lbusett
    Jun 7, 2017 at 20:54

1 Answer 1


I discovered in that in IDL and bandmath that the layers have to be stacked in a single file via ENVIMetaspectralRaster in order for MATH_DOIT to process. This (ENVIMetaspectralRaster) is what I had to use as I am coding in a previous version of IDL. IDL 8.4. Current version is 8.6.

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.