The CreateLayer function method creates and returns a new layer object. The layer is displayed in the parent view. The following layers are supported:


; Launch the application
e = ENVI()
; Create an ENVIRaster
file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $
  SUBDIRECTORY = ['data'])
raster = e.OpenRaster(file)
view = e.GetView()
; Create a true-color layer
layer = view.CreateLayer(raster)


Result = ENVIView.CreateLayer(Data [, Keywords=value])

Return Value

This method returns a reference to an ENVIAnnotationLayer, ENVIGridLinesLayer, ENVIRasterLayer, ENVIRasterSeriesLayer, or ENVIVectorLayer object.



Specify one of the following:

  • An ENVIAnnotationSet object
  • An ENVIRaster object. If you do not specify any keywords, the layer is created as a true-color or greyscale image.
  • An ENVIRasterSeries object
  • An ENVIVector object
  • A string of the base filename of world data included with your ENVI installation (accessed through the File > Open World Data menu). Data courtesy of Natural Earth. Valid strings include coastlines, countries, geographic_lines, lakes, minor islands, populated_places, ports, rivers, roads, states_provinces, gmted2010, and shaded_relief.


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


Set this keyword to a one-element array specifying the band index to be displayed, or a three-element array specifying the band indices (0-based) to be displayed as R, G, and B. This keyword is valid only if Data is an ENVIRaster. See Open Files for details on how ENVI automatically determines the bands to display. If the 'default bands' field is set in the associated ENVI header file, then those bands will be displayed.


Set this keyword to load a color-infrared (CIR) image if Data is an ENVIRaster. This keyword is ignored if BANDS is set, and it takes precedence over any default bands values set in the metadata.


If this keyword is set, all of the layers will be removed from the view prior to displaying the new layer.


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 load a true-color RGB image if Data is an ENVIRaster. This keyword is ignored if BANDS is set, and it takes precedence over any default bands values set in the metadata.

Version History



ENVI 5.1

Added RGB keyword

API Version


See Also

ENVIView, ENVIView::GetLayer, ENVIAnnotationLayer, ENVIAnnotationSet, ENVIGridLinesLayer, ENVIRasterLayer, ENVIRaster, ENVIRasterSeriesLayer, ENVIRasterSeries, ENVIVectorLayer, ENVIVector