Convert ENVI standard format files to .tif files - based on ENVI library functions

Convert ENVI standard format files to .tif files - based on ENVI library functions
1. Purpose
(1) Understand the ENVI standard format file
(2) Learn how to use ENVI library functions to convert ENVI standard format files into .tif files
2. Start time: April 10, 2017 Finish time: April 11, 2017

3. ENVI standard format (understand, not necessarily accurate)
   The ENVI standard format file usually includes a header file (suffix .hdr) and a corresponding image file (usually .img format). The header file contains the basic information of the data.

4.IDL code
;******************************************************;
;Program purpose: use ENVI library functions to convert ENVI standard format data to .tif file example
; April 12, 2017
;******************************************************;

PRO Img2Tif_Example

  ENVI_File = 'F:\1_Data\drought_2003_SouthChina.2001'
  Print,ENVI_File
  ; set the operating environment
  COMPILE_OPT IDL2
  ENVI,/RESTORE_BASE_SAVE_FILES ; The /RESTORE_BASE_SAVE_FILES keyword controls whether to display the ENVI classic interface
  ENVI_BATCH_INIT ; don't drop
  
  ; get the file ID
  ENVI_OPEN_FILE,ENVI_File,R_FID = FID
  Print, FID
  ;Query the basic information of the header file
  ENVI_File_Query,FID,Ns=ns,NL=nl,NB=nb,Data_Type=data_type,Dims=dims,INTERLEAVE=interleave
  Print,'Number of columns=',ns,String(13B),'Number of rows=',nl,string(13B),'Number of bands=',nb
  
  ;Format conversion
  Tif_File = 'F:\1_Data\ChinaSouthAlbedo2001001.tif' ; output file name
  ENVI_OUTPUT_TO_EXTERNAL_FORMAT,FID=FID,Dims=dims,POS=nb[0],Out_Name=Tif_File,/TIFF ;POS keyword controls the number of output bands
  Print,'finished'
  

END
5. Function description
       The main functions used in the joint programming of ENVI_IDL that converts the ENVI standard format to .tif format include the initialization function of the ENVI runtime environment (COMPILE_OPT IDL2, ENVI, ENVI_BATCH_INIT); FID), ENVI_FILE_QUERY (get the basic information of the file)); format conversion function (ENVI_OUTPUT_TO_EXTERNAL_FORMAT) and other 6 main functions.
5.1  ENVI_OUTPUT_TO_EXTERNAL_FORMAT
       ENVI_OUTPUT_TO_EXTERNAL_FORMAT [, / ARCVIEW ] [, / ASCII ] [, BLOCK_HEIGHT = long integer ] [,              BLOCK_WIDTH = long integer ], DIMS = array [, / ENVI ] [, / ERDAS ] [, / ERMAPPER ], FID = file ID [, FIELD = array ] [,    / IMAGINE ] [, / JP2 ] [, / NITF ] [, OUT_BNAME = string array ], OUT_NAME = string [, / PCI ], POS = array [, / TIFF ]

6. References
1.https://www.harrisgeospatial.com/docs/ENVI_OUTPUT_TO_EXTERNAL_FORMAT.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324383154&siteId=291194637