This document is archived and information here might be outdated.  Recommended version.


Deferred evaluation (ArcObjects .NET 10.5 SDK)

Deferred evaluation


Summary
This topic provides a brief discussion on deferred evaluation in spatial analysis operations.

About deferred evaluation

To increase overall performance, raster outputs from Spatial Analyst methods are not computed until they are used. This deferred evaluation of output datasets can result in outputs never being calculated if they are never used. Any use of the output, including creating a layer, examining the height and width of the output, or making the dataset permanent, triggers evaluation of the expression to create the dataset.
 
Global functions, such as CostDistance, are not deferred and are evaluated when executed, whether the output is referred to or not. For all other operations, the evaluation of the output is deferred until the output dataset is used.
 
The following code example forces the evaluation of the Slope method by querying the height of the output dataset:
[C#]
public void ForceEvaluation()
{
    // Gets an elevation raster from disk.
    IRasterDataset rasterDataset_Elevation=OpenRasterDataset("C:\\Spatial", 
        "elevation");

    // Queries the RasterSurfaceOp.
    ISurfaceOp surfaceOp=new RasterSurfaceOpClass();

    // Creates a geodataset to store the results of the operation.
    IGeoDataset geoDataset_Elevation=(IGeoDataset)rasterDataset_Elevation;
    System.Object zFactor=Type.Missing;
    IGeoDataset geoDataset_Output=surfaceOp.Slope(geoDataset_Elevation,
        esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref zFactor);

    // Forces the evaluation by querying the Height property.
    IRasterProps rasterProps=(IRasterProps)geoDataset_Output;
    Int32 int32_height=rasterProps.Height;
    Console.WriteLine(int32_height.ToString());
}
[VB.NET]
Public Sub ForceEvaluation()
    ' Gets an elevation raster from disk.
    Dim rasterDataset_Elevation As IRasterDataset=OpenRasterDataset("C:\Spatial ", "elevation")
    
    ' Queries the RasterSurfaceOp.
    Dim surfaceOp As ISurfaceOp=New RasterSurfaceOpClass
    
    ' Creates a geodataset to store the results of the operation.
    Dim geoDataset_Elevation As IGeoDataset=CType(rasterDataset_Elevation, IGeoDataset)
    Dim geoDataset_Output As IGeoDataset=surfaceOp.Slope(geoDataset_Elevation, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees)
    
    ' Forces the evaluation by querying the Height property.
    Dim rasterProps As IRasterProps=CType(geoDataset_Output, IRasterProps)
    Dim int32_height As Int32=rasterProps.Height
    Console.WriteLine(int32_height.ToString)
    
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic: Spatial Analyst ArcGIS Desktop Basic: Spatial Analyst
ArcGIS Desktop Standard: Spatial Analyst ArcGIS Desktop Standard: Spatial Analyst
ArcGIS Desktop Advanced: Spatial Analyst ArcGIS Desktop Advanced: Survey Analyst