This function constructs an ENVIRaster from an input raster and an input mask. A pixel value of 0 in the input mask indicates that pixel location should be masked in the output.

The result is a virtual raster, which has some additional considerations with regard to methods and properties. See Virtual Rasters for more information, including how they differ from ENVITasks.

The equivalent task is MaskRaster.


; 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)
; Create a raster mask
mask = (raster.GetData(BAND=0) GE 220)
; Save the mask to a file
file = e.GetTemporaryFilename()
maskRaster = ENVIRaster(mask, URI=file)
; Apply the mask to the input raster
maskedRaster = ENVIMaskRaster(raster, MaskRaster)
; Display the new raster. The masked areas are transparent.
view = e.GetView()
layer = view.CreateLayer(maskedRaster)

You can optionally save the masked raster to disk. However, be sure to set the DATA_IGNORE_VALUE keyword on the ENVIRaster::Export method as follows:

; Save the masked raster to a file
outFile = e.GetTemporaryFilename()
maskedRaster.Export, outFile, 'ENVI', DATA_IGNORE_VALUE=0

See Data Ignore Value for more information on choosing a suitable value.


Result = ENVIMaskRaster(Input_Raster, Input_Mask [, Keywords=value])

Return Value

The method returns an ENVIRaster, where the applied mask alters the pixel state of the raster. Use the PIXEL_STATE keyword of ENVIRaster::GetData or ENVIRasterIterator::GetData to determine which pixels to process. See Raster Pixel State for more details.



Specify an input ENVIRaster.


Specify an ENVIRaster with the same spatial dimensions as Input_Raster.


This virtual raster inherits methods and properties from ENVIRaster; however the following methods will override the ENVIRaster methods:




ERROR (optional)

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.

INVERSE (optional)

Set this keyword to invert the input mask. A pixel value that is non-zero will be masked in the output.


Specify a string that identifies the raster.

Version History

ENVI 5.2.1


ENVI 5.3.1

Documented the dehydrated form of this virtual raster

ENVI 5.4

Added Dehydrate and Hydrate methods; added NAME keyword

API Version


See Also

MaskRaster Task, ENVIRaster, ENVIDataValuesMaskRaster, ENVIROIMaskRaster, ENVIVectorMaskRaster, CalculateCloudMaskUsingFMask Task, Masks