This function is used to create ENVI objects like ENVIRaster, ENVIMaskRaster, and ENVIVector from a hash description of their properties instead of using their dedicated routines. Any ENVI object with a Dehydrate method can be used in ENVIHydrate. The ability to dehydrate and hydrate ENVI objects gives you the following capabilities:

  • Store the object state, then restore it in a later IDL session.
  • Apply a virtual raster chain of processes by building a hash instead of calling multiple functions.

ENVIHydrate performs these items using recursion. It performs a depth-first traversal by looking for any values that are hash objects, then calls itself recursively to make sure object inputs have been rebuilt first. It looks for the factory key in the hash to identify the type of object to create. The rest of the keys in the hash are mapped to keywords in the function.

For additional information, see What are Hydrate and Dehydrate routines used for?


The following code creates a virtual subsetted Normalized Difference Vegetation Index (NDVI) raster, stores the hash as a JSON file, and restores it in another session.

; 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)
; Subset the raster
subsetRaster = ENVISubsetRaster(Raster, $
; Compute NDVI on the subset raster
ndviRaster = ENVISpectralIndexRaster(subsetRaster, 'NDVI')
; Display the NDVI
view = e.GetView()
layer = view.CreateLayer(ndviRaster)
; Get the hash representation of the virtual raster chain
ndviHash = ndviRaster.Dehydrate()
; Store hash in JSON format
jsonFile = e.GetTemporaryFileName('.json')
OPENW, LUN, jsonFile, /GET_LUN
; Close ENVI
; Relaunch and create the NDVI raster from file
e = ENVI()
ndviRestoredHash = JSON_PARSE(jsonFile)
ndviRestoredRaster = ENVIHydrate(ndviRestoredHash)
; Display the restored raster
view = e.GetView()
layer = view.CreateLayer(ndviRestoredRaster)


Result = ENVIHydrate(Hash [, ERROR=value])

Return Value

This function returns a reference to an object created by the factory function identified by the factory key in the input Hash.



An IDL hash object that describes the object to be created. The hash must contain a factory key whose value is a scalar string with the name of the object type to create. See the Dehydrate method of the object type (for example, ENVIRasterMetadata::Dehydrate) for a description of the keys that can be used.



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.3.1


API Version


See Also

ENVIHydratable::Dehydrate, ENVICoordSys::Dehydrate, ENVIGCPSet::Dehydrate, ENVIGLTRasterSpatialRef::Dehydrate, ENVIGridDefinition::Dehydrate, ENVIPseudoRasterSpatialRef::Dehydrate, ENVIRaster::Dehydrate, ENVIRasterMetadata::Dehydrate, ENVIRasterSeries::Dehydrate, ENVIRPCRasterSpatialRef::Dehydrate, ENVISpectralLibrary::Dehydrate, ENVIStandardRasterSpatialRef::Dehydrate, ENVITiePointSet::Dehydrate, ENVITime::Dehydrate, ENVIVector::Dehydrate