The WriteMetadata method saves all metadata associated with a raster to a header file (.hdr) on disk. The header file is in the same directory as the data file. If you do not have permission to write the metadata file to that directory, the file is written to an auxiliary location specified by the Auxiliary File Directory preference.

Although this method is automatically called by the ENVIRaster::Save method, you can call ENVIRaster::WriteMetadata directly to save the metadata independently of saving the raster data.

This method does not write the 'read procedures' metadata field to an ENVIRasterMetadata object in custom file readers.

Example


; Launch the ENVI application
e=ENVI()
 
; Define the output filename.
outFile=e.GetTemporaryFilename()
 
; Generate raster data.
data=Bytarr(500,500,3)
data[*,*,0]=Bytscl(Dist(500))
data[*,*,1]=Shift(Bytscl(Dist(500)),167,167)
data[*,*,2]=Shift(Bytscl(Dist(500)),334,334)
 
; Create the raster dataset and save to file on disk.
raster=ENVIRaster(data, URI=outFile)
raster.Save
 
; Add metadata to raster for band names and wavelengths.
raster.Metadata.UpdateItem,'band names',['Red','Green','Blue']
raster.Metadata.AddItem,'wavelength units','Micrometers'
raster.Metadata.AddItem,'wavelength',[0.660,0.560,0.485]
 
; Update the ENVI format *.hdr file with new metadata.
raster.WriteMetadata
 
; Close and re-open the raster dataset.
raster.Close
raster=e.OpenRaster(outFile)
 
; Obtain the current view and load the raster as a layer.
view=e.GetView()
layer=view.CreateLayer(raster)

Syntax


ENVIRaster.WriteMetadata [, ERROR=variable]

Keywords


Keywords are applied only during the initial creation of the object.

ERROR

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

Introduced

API Version


4.3

See Also


ENVIRasterMetadata, ENVIRaster, Raster Metadata, EditRasterMetadata Task, ENVIRaster::Save