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

  >  Docs Center  >  ENVI API  >  Crop Science  >  ENVIAgCalculateCropMetrics



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 ENVIAgCountAndRasterizeCropsTask 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 ENVIAgCalculateAndRasterizeCropMetricsTask or ENVIAgCalculateAndRasterizeCropMetricsWithSpectralIndexTask.

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 the ENVISpectralIndexTask topic in ENVI Help for a full list of spectral indices. You can run ENVIQuerySpectralIndicesTask 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 ENVIAgCountAndRasterizeCropsTask 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 the Manage Errors topic in ENVI Help for more information on error handling.


Specify a string with a fully qualified filename and path, to save an ENVIAgCrops object to a JSON-formatted text file.

Version History



See Also

ENVIAgCalculateCropMetricsTask, ENVIAgCrops, ENVICropCount, ENVIAgCalculateAndRasterizeCropMetricsTask, ENVIAgCalculateAndRasterizeCropMetricsWithSpectralIndexTask

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