Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.

  >  Docs Center  >  ENVI API  >  Data Control  >  ENVIPixelwiseBandMathRaster



This function constructs an ENVIRaster from a source raster that has a mathematical expression applied on a pixel-by-pixel basis. If any of the bands referenced by the expression have a bad pixel state (due to masking or a data ignore value) and you set the DATA_IGNORE_VALUE keyword, then the corresponding output pixel will have a bad pixel state and will be transparent.

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


This example calculates an Enhanced Normalized Difference Vegetation Index (ENDVI, source: MaxMax.com).

; 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)
; Calculate enhanced NDVI
expression = 'float((b4 + b2) - 2*b1) / float((b4 + b2) + 2*b1)'
bandMathRaster = ENVIPixelwiseBandMathRaster(raster, expression)
; Display the result
View = e.GetView()
Layer = View.CreateLayer(bandMathRaster)


Result = ENVIPixelwiseBandMathRaster(Input_Raster, Expression, ERROR=variable)

Return Value

This routine returns a reference to an ENVIRaster.



Specify the input ENVIRaster.


Enter a string indicating the mathematical expression.

  • Name the band variables as bx, where x is the order of the band in the raster. For example, b1 is the first band in the raster, b2 is the second band, etc.
  • You can specify any IDL function, including user-defined functions that can be found in !PATH.
  • The expression cannot change the dimensions of the raster. Functions such as TOTAL, MIN, and MEAN reduce an array to a scalar, so they are not allowed unless you use them like MIN([b1, b2, b3]) or b1 / MAX(b1).
  • The expression must evaluate to a scalar so that a single-band output raster is created.
  • When using division in an expression, be sure to add float in the denominator. See the above example.


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





Set this keyword to a numeric pixel value that ENVI should ignore when subsequently processing data or computing statistics from the output image.

  • This value should be different from any other pixel values in the raster, including expected values from the band math expression.
  • This value is stored as raster metadata. If you use the ENVIRaster::Export method to export the raster, you will not have to remember the value you used for DATA_IGNORE_VALUE.

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.


Specify a string that identifies the raster.

Version History

ENVI 5.3, Service Pack 1


ENVI 5.4

Added Dehydrate and Hydrate methods; added NAME keyword

ENVI 5.4, Service Pack 1

Expanded the Expression argument to include IDL functions and other mathematical operations besides +, -, *, and /.

API Version


See Also

ENVIRaster, ENVIPixelwiseBandMathRasterTask

© 2018 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us