The PixelCount function method returns the number of pixel locations that comprise the ROI for the given ENVIRaster.


; Launch the application
e = ENVI()
; Open the first input file
file = Filepath('qb_boulder_msi', ROOT_DIR=e.Root_Dir, $
msiRaster = e.OpenRaster(file)
; Open the second input file
file = Filepath('qb_boulder_pan', ROOT_DIR=e.Root_Dir, $
panRaster = e.OpenRaster(file)
; Define a new ROI with a polygon
roi = EnviRoi(NAME='Tennis Court', COLOR='Green')
data = [[480872.7214d, 4428333.0664d], $
       [480908.2576d, 4428333.0664d], $
       [480907.5742d, 4428265.4108d], $
       [480873.3289d, 4428265.7720d], $
       [480872.7214d, 4428333.0664d]]
roi.AddGeometry,  data, coord_sys=msiRaster.SpatialRef.Coord_Sys_Str, /POLYGON
; Print the number of pixels contained in this polygon for qb_boulder_msi
PRINT, 'number of qb_boulder_msi pixels = ', roi.PixelCount(msiRaster)
; Print the number of pixels contained in this polygon for qb_boulder_pan
PRINT, 'number of qb_boulder_pan pixels = ', roi.PixelCount(panRaster)


Result = ENVIROI.PixelCount(Raster [, ERROR=variable])

Return Value

Returns the unsigned long 64-bit integer value of pixel locations for an ROI for the given ENVIRaster.



The ENVIRaster reference that establishes the coordinate system reference of the ROI pixel locations.



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.

Version History

ENVI 5.1


API Version


See Also

ENVIROI, ENVIRaster, ENVIROI::PixelAddresses