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.



6207 Rate this article:
1.3

How to programmatically subset an image with a vector file (ENVI Classic)

This Help Article includes example code that can be used to subset an image using a vector file and to mask the areas outside of the vector boundaries. This is similar functionality to ENVI's  'Subset Data via ROI' found under the Basic Tools menu, but allows for the use of a vector file.
 
The following code provides methods to subset an image with an ENVI vector file and to mask the background values to only the area within the vector. The code example includes a few unexposed routines and keywords which make this a relatively simple process. The example uses ENVI's 'world_dem' image and an ENVI vector created from the 'states.shp' sample vector file.

The code example includes the undocumented routines, 'evf_open', 'envi_roi_compute_spatial_boundry', and 'envi_mask_doit'. Because these routines are not currently exposed to users, the syntax is subject to change in future versions of ENVI.  Exelis VIS support of these routines is limited.

pro subset_by_evf
compile_opt idl2     
  
;select input file to subset
fname = 'C:\Program Files\ITT\IDL\IDL80\products\envi48\data\world_dem'
;fname = files
envi_open_file, fname, r_fid=fid
if (fid eq -1) then return   
  
envi_file_query, fid, bnames=bnames, sname=sname, nb=nb
pos=lindgen(nb)  
  
;open vector file to use for subset and get id
evf_fname = 'C:\Program Files\ITT\IDL\IDL80\products\envi48\data\vector\states_.evf'
  
;make sure envi vector routine is available
envi_check_save, /vector 
  
;open the vector and get its ID
evf_open, evf_fname, vec=vec, /no_warning
evf_id = vec.id  
  
;compute the spatial boundary based on the evf using ROI routines (undocumented routine) - this will provide the DIMS to use to subset
roi_ids = envi_get_roi_ids(fid=fid, /include_evfs)
envi_roi_compute_spatial_boundry, roi_ids, dims, fid=fid  
  
;resize the original image by the new dimensions
envi_doit, 'resize_doit', fid=fid, dims=dims, pos=pos, $
   rfact=[1.,1.], /in_memory, r_fid=sub_fid  
  
envi_file_query, sub_fid, ns=ns, nl=nl, dims=dims  
  
;generate a mask from the evf (undocumented routine) - you need to mask areas outside of EVF boundaries if the EVF is not a rectangle
; this is the same as using Basic Tools ->Subset data via ROIs and masking the outside of the ROI/EVF boundary
envi_mask_doit, evf_id=evf_id, evf_fid=sub_fid, ns=ns, nl=nl, and_or=0, $
    /inside, /in_memory, r_fid=m_fid  
  
;apply the mask to the subset image
out_name=sname+'_subset'
envi_mask_apply_doit, fid=sub_fid, pos=pos, dims=dims, m_fid=m_fid, m_pos=0l, $
   value=-9999, out_bname=bnames, out_name=out_name 
envi_evf_close, evf_id  
  
      ;clear out open files to avoid FID confusion when opening new files
      fids=envi_get_file_ids()
      for j=0, n_elements(fids)-1 do begin
        envi_file_mng, id=fids[j], /remove
 
      endfor
  
END

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 »