X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4966 Rate this article:
No rating

ENVI 5: Displaying images using ENVI's new API and running ENVI Classic 'DOIT' routines

The following example code demonstrates how to open an image in the ENVI 5 display and access the ENVI Classic image File ID (FID) to perform ENVI classic 'DOIT' routines.  Specifically, the code will run a Quick Atmospheric Correction (Quac) and then calculate the Soil-Adjusted Vegetation Index (SAVI) for a QuickBird image from the ENVI distribution.  After running the DOIT procedures, it accesses the raster object from the returned FID and performs some simple display manipulations in the ENVI 5 display.  The code is commented throughout to aid in understanding the programming calls.

pro calculate_savi
 
  ; Set compile options
  compile_opt IDL2
   
  ; General error handler
  CATCH, err
  if (err ne 0) then begin
    CATCH, /CANCEL
    if OBJ_VALID(e) then $
      e.ReportError, 'Please provide a valid multispectral file', /INFORMATION
    MESSAGE, /RESET
    return
  endif
   
  ; Get ENVI session
  e = ENVI(/CURRENT)
 
  ; Get the User Interface (UI) object
    UI = e.UI
   
  ; Open ENVI's Quickbird Dataset
    file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, SUBDIRECTORY = ['data'])
    raster = e.OpenRaster(file)
 
 ; Now display the chosen raster
    view= e.GetView()
    layer = view.CreateLayer(raster, bands=[3,2,1])
   
  ; Return a file ID to pass to ENVI DOIT routines
    fid = ENVIRasterToFID(raster) 
 
  ; use FID to query file to get parameters needed for DOIT routines
   ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, dims=dims, sname=sname
    pos=lindgen(nb)
  
  ; set output directory
    outDir = 'c:\testing\dataout\'  
     
  ; calibrate to reflectance using Quac
    ENVI_DOIT, 'ENVI_QUAC_DOIT', fid=fid, dims=dims, pos=pos, quac_sensor='QuickBird', $
      out_name=outDir+sname+'_refl.dat', r_fid=refl_fid
 
  ; set up parameters for MATH_DOIT to calculate SAVI
  ; SAVI expression
    exp = '((float(b4) - float(b3)) / ((float(b4) + float(b3)) + 0.5)) * 1.5'
    in_pos = [2,3]
    in_fid = [refl_fid, refl_fid]
         
   ; call MATH_DOIT
     ENVI_DOIT, 'MATH_DOIT', fid=in_fid, pos=in_pos, dims=dims, exp=exp, $
       out_name=outDir+sname+'_SAVI.dat', r_fid=savi_fid   
    
   ;get raster object from FID
    newRaster = ENVIFidToRaster(savi_fid)
    
   ; get all the layers
    layers = view.getLayer(/ALL)
 
  ; find the savi raster and set stretch
    foreach l,layers do begin
      if l.data eq newRaster then l.quick_stretch='linear 5%'
    endforeach
      
   ; set view to full extent 
     view.Zoom, /full_extent
     

end


Review on 12/31/2013 MM

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »