This function calculates statistics from a raster and an associated ENVIAgCrops object. For example, if the input raster is a vegetation index such as NDVI, the crop metrics describe the health of the crops. You can run ENVIAgCropCount or AgCountAndRasterizeCrops Task to create an ENVIAgCrops object before running ENVIAgCalculateCropMetrics. Or, you can use an ENVIAgCrops file that you created and saved earlier.

To create a raster that you can visualize from crop metrics, use AgCalculateAndRasterizeCropMetrics Task or AgCalculateAndRasterizeCropMetricsWithSpectralIndex Task.

This object is part of ENVI Crop Science, which requires a separate license and installation.


This example performs the following steps:

  1. Opens an orthophoto of a citrus orchard.
  2. Creates a spectral index raster to make the citrus trees bright against the background. A Normalized Difference Vegetation Index (NDVI) works well in this case.
  3. Tip: See SpectralIndex Task for a complete list of spectral indices. You can run QuerySpectralIndices Task to see what indices are available for your particular image.

  4. Uses the AgCropCount function to count the trees and to create an ENVIAgCrops object.
  5. Uses the AgCalculateCropMetrics function to calculate metrics from the NDVI image.
  6. Prints the NDVI metrics.
; Start the application
; Open an input file
File = Filepath('CitrusOrthophoto.dat', $
  Subdir=['data','crop_science'], $
Raster = e.OpenRaster(File)
; Preprocess the image so that crops are bright.
NDVIImage = ENVISpectralIndexRaster(Raster, 'NDVI')
; Count the crops and output an ENVIAgCrops object
outCrops = ENVIAgCropCount(NDVIImage, 2.0, 5.0, $
; Calculate crop metrics
outCropMetrics = ENVIAgCalculateCropMetrics(NDVIImage, outCrops)
; Print the crop metrics
Print, outCropMetrics


Result = ENVIAgCalculateCropMetrics(Input_Raster, Input_Crops [, Keywords=value])

Return Value

This function returns a reference to an ENVIAgCrops object.



Specify a single-band input ENVIRaster. With multispectral images, you must first create a single-band spectral subset.


Specify an input ENVIAgCrops object. You can run ENVIAgCropCount or AgCountAndRasterizeCrops Task to create an ENVIAgCrops object. Or, you can use an ENVIAgCrops file that you created and saved earlier.






The output ENVIAgCrops object contains the following properties, in addition to the standard ENVIAgCrops properties:


The maximum pixel value for each crop.


The mean pixel value for each crop.


The minimum pixel value for each crop.


The standard deviation pixel value for each crop.


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 with a fully qualified filename and path, to save an ENVIAgCrops object to a JSON-formatted text file.

Version History

Crop Science 1.0


See Also

AgCalculateCropMetrics Task, ENVIAgCrops, ENVICropCount, AgCalculateAndRasterizeCropMetrics Task, AgCalculateAndRasterizeCropMetricsWithSpectralIndex Task