The Export method saves a raster to a specific format. This method creates a new file, but it does not change the existing raster.


; Launch the application
e = ENVI()
; Create an ENVIRaster
file = FILEPATH('qb_boulder_pan', ROOT_DIR=e.ROOT_DIR, $
  SUBDIRECTORY = ['data'])
raster1 = e.OpenRaster(file)
; Create a temporary output file
newFile = e.GetTemporaryFilename('tif')
; Export a subset of the raster as a TIFF file
subRaster = ENVISubsetRaster(raster1, SUB_RECT=[500,2500,1699,3999])
subraster.Export, newFile, 'TIFF'
; Open the TIFF file
raster2 = e.OpenRaster(newFile)
view = e.GetView()
layer = view.CreateLayer(raster2)

Also see More Examples below.


ENVIRaster.Export, URI, Format [, Keywords=value]



A scalar string denoting the fully qualified file path in which the raster will be saved.


A scalar string denoting the format in which the raster(s) will be saved. An error will be thrown if the format is unrecognized or unsupported by the raster. The valid string values are as follows; they are not case-sensitive:

  • ENVI
  • NITF: National Imagery Transmission Format (NITF); set the NITF_COMPRESSION keyword as needed.
  • TIFF


Keywords are applied only during the initial creation of the object.

Note: Keywords not associated with the given format are quietly ignored.


Set this keyword to specify a unique data value to use on output for any pixels that have a pixel state of non-zero (No Data, Mask, Outside of ROI). If the ENVIRasterMetadata object associated with the ENVIRaster already contains a data ignore value and you do not set this keyword, that value will be used. For more details on pixel state, see Raster Pixel State.


Set this keyword to a named variable that will contain any error message issued during execution of this routine. If no error occurs, the ERROR variable will be set to a null string (''). If an error occurs and the routine is a function, then the function result will be undefined.

When this keyword is not set and an error occurs, ENVI returns to the caller and execution halts. In this case, the error message is contained within !ERROR_STATE and can be caught using IDL's CATCH routine. See IDL Help for more information on !ERROR_STATE and CATCH.

See Manage Errors for more information on error handling in ENVI programming.


Set this keyword to a string specifying the interleave of the raster:

String Interleave Data Array

Band interleaved by line

[ncolumns, nbands, nrows]


Band interleaved by pixel

[nbands, ncolumns, nrows]

Band sequential

[ncolumns, nrows, nbands]

  • This keyword is optional; the default value is bsq if you do not set it.
  • You cannot use the INTERLEAVE keyword for NITF output (if the Format argument is set to nitf). By default, NITF three-band images that use any of the JPEG DCT compression modes will output with BIP interleave; otherwise, the default interleave is BSQ.
  • TIFF files do not support BIL interleave, only BIP and BSQ.


If you specify NITF as the Format value, set this keyword to a string denoting the NITF compression type, listed below.

The following NITF_COMPRESSION options are only available for use when the NITF Version is set to NITF02.10 or NSIF01.00 in ENVI Preferences (NITF > NITF File Settings), and the data type is byte, integer, unsigned integer, long integer, and unsigned long integer:

  • epje num lossless
  • epje vis lossless
  • npje num lossless
  • npje vis lossless
  • transcode epje to npje: Only works for NITF files that are C8-compressed and are not spatially subsetted
  • transcode npje to epje: Only works for NITF files that are C8-compressed and are not spatially subsetted

The following options work in all supported NITF versions for rasters that have one or three bands, and the data type is byte:

  • jpeg dct (high)
  • jpeg dct (low)
  • jpeg dct (medium)

The default value is no compression.

More Examples

The following example creates a mask from a region of interest (ROI) and applies the mask to the source raster. If you were to display the masked raster immediately after creating it, you would not see the masked pixels. In this case, you must export the masked raster and set the DATA_IGNORE_VALUE keyword to 0. When you reopen and display the masked raster, you will see the masked pixels. See How do I set a data value to ignore? for details.

; Start the application
e = ENVI()
; Open an input file
file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $
  SUBDIRECTORY = ['data'])
raster = e.OpenRaster(file)
; Open a multi-part ROI
fileName = Filepath('qb_boulder_roi.xml', SUBDIR=['data'], $
rois = e.OpenRoi(fileName)
; Create a masked raster based on the water ROI.
; Pixels outside of the ROI are masked.
mask = ENVIRoiMaskRaster(raster, rois[2])
; Save the masked raster to disk
outFile = e.GetTemporaryFilename()
mask.Export, outFile, 'ENVI', DATA_IGNORE_VALUE=0

Version History

ENVI 5.1


API Version


See Also

ENVIRaster, ENVIRaster::Save