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#] 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:
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 for Desktop Basic: Spatial Analyst | ArcGIS for Desktop Basic: Spatial Analyst |
ArcGIS for Desktop Standard: Spatial Analyst | ArcGIS for Desktop Standard: Spatial Analyst |
ArcGIS for Desktop Advanced: Spatial Analyst | ArcGIS for Desktop Advanced: Survey Analyst |