Data processing in spatial analysis operations


Summary This topic reviews the processing of raster data, such as how to create permanent data and how to avoid internal data conversion when running spatial analysis operations.

About data processing in spatial analysis operations

The processing of raster data in Spatial Analyst in ArcGIS 9.3.1 and earlier is only performed on an ESRI grid and therefore, data is converted internally when required. The output from any Spatial Analyst operation is also temporary and in ESRI grid format. These temporary datasets can be made permanent and saved to any of the supported raster formats with the use of additional code.
Two new interfaces, IRasterAnalysisGlobalEnvironment and IRasterOpBase, are introduced in ArcGIS 10 to allow for the processing of raster data in Spatial Analyst without the need to convert to ESRI grid format. Setting IRasterAnalysisGlobalEnvironment.AvoidDataConversion to false (the default setting) is the same as in previous versions of ArcGIS.
Setting IRasterAnalysisGlobalEnvironment.AvoidDataConversion to true ensures that all processing is performed natively on the raster data. This improves the overall performance as there is no need for the input data to be converted to ESRI grid format. The output data, however, is still temporary rasters in ESRI grid format.
The IRasterOpBase interface provides a mechanism to specify the name of the output data and also its workspace before the operation is performed, which results in the output being directly written to the required format. This means that the output data is permanent and in the required format, and no conversion of the input raster to ESRI grid is done. 
Please note that the output name and workspace property is reset after the operation is performed and must be specified with each method or subsequent run.
The following summarizes IRasterAnalysisGlobalEnvironment:
  • If IRasterAnalysisGlobalEnvironment.AvoidDataConversion is not used or is set to false, and an output name is specified via IRasterOpBase, the input data is read natively and the output data is permanent in the requested format.
  • If IRasterAnalysisGlobalEnvironment.AvoidDataConversion is set to true, and IRasterOpBase is not used, the data is read natively; however, the output is a temporary ESRI grid in the user-defined workspace.
  • If neither IRasterAnalysisGlobalEnvironment nor IRasterOpBase is used, conversion to an ESRI grid is done on the input data and the output is a temporary ESRI grid.
The following code example shows how to set the AvoidDataConversion property at the global level:
[C#]
// Set AvoidDataConversion to true for the RasterAnalysis object.
IRasterAnalysisGlobalEnvironment analysisGlobalEnv = new RasterAnalysisClass();
analysisGlobalEnv.AvoidDataConversion = true;
[VB.NET]
' Set AvoidDataConversion to true for the RasterAnalysis object.
Dim analysisGlobalEnv As IRasterAnalysisGlobalEnvironment = New RasterAnalysisClass()
analysisGlobalEnv.AvoidDataConversion = True
The following code example shows how to set AvoidDataConversion property at the op level:
[C#]
public void AvoidDataConversionForThisOp()
{
    // Gets an elevation raster from disk.
    // NOTE: The method OpenRasterDataset was created previously in this document.
    // It is not a standard ArcObject's function.
    IRasterDataset elev1 = OpenRasterDataset("C:\\Spatial", "elevation");

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

    // Sets AvoidDataConversion to True for surfaceOp
    IRasterAnalysisGlobalEnvironment analysisGlobalEnv;
    analysisGlobalEnv = (IRasterAnalysisGlobalEnvironment)surfaceOp;
    analysisGlobalEnv.AvoidDataConversion = true;

    // Omits Z factor
    System.Object zFactor = Type.Missing;

    // Creates a geodataset to store the results and runs the operation.            
    IGeoDataset outSlope;
    outSlope = surfaceOp.Slope((IGeoDataset)elev1,
        esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref zFactor);

    // Save output raster
    ISaveAs2 outSave = (ISaveAs2)outSlope;

    IWorkspaceFactory wsFact = new RasterWorkspaceFactoryClass();
    IWorkspace ws = wsFact.OpenFromFile("c:\\temp", 0);
    outSave.SaveAs("outSlope1.tif", ws, "TIFF");
}
[VB.NET]
Public Sub AvoidDataConversionForThisOp()
    ' Gets an elevation raster from disk.
    ' NOTE: The method OpenRasterDataset was created previously in this document.
    ' It is not a standard ArcObject's function.
    Dim elev1 As IRasterDataset = OpenRasterDataset("C:\Spatial", "elevation")
    
    ' Queries the RasterSurfaceOp.
    Dim surfaceOp As ISurfaceOp = New RasterSurfaceOpClass()
    
    ' Sets AvoidDataConversion to True for surfaceOp
    Dim analysisGlobalEnv As IRasterAnalysisGlobalEnvironment
    analysisGlobalEnv = CType(surfaceOp, IRasterAnalysisGlobalEnvironment)
    analysisGlobalEnv.AvoidDataConversion = True
    
    'Omits Z factor
    Dim zFactor As System.Object = Type.Missing
    
    ' Creates a geodataset to store the results and runs the operation.
    Dim outSlope As IRaster
    outSlope = surfaceOp.Slope(elev1, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, zFactor)
    
    ' Save output raster
    Dim outSave As ISaveAs2 = CType(outSlope, ISaveAs2)
    
    Dim wsFact As IWorkspaceFactory = New RasterWorkspaceFactoryClass()
    Dim ws As IWorkspace = wsFact.OpenFromFile("c:\temp", 0)
    outSave.SaveAs("outSlope1.tif", ws, "TIFF")
End Sub
The following code example shows how to specify an output name using IRasterOpBase:
[C#]
public void SetOutputName()
{
    // Gets an elevation raster from disk.
    // NOTE: The method OpenRasterDataset was created previously in this document.
    // It is not a standard ArcObject's function.                
    IRasterDataset elev1 = OpenRasterDataset("C:\\Spatial", "elevation");

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

    // Sets the output name
    // creates workspace name
    IWorkspaceFactory wsFactory;
    wsFactory = new RasterWorkspaceFactoryClass();

    IWorkspace ws;
    ws = wsFactory.OpenFromFile("C:\\temp", 0);

    IDataset dataSet;
    dataSet = (IDataset)ws;
    IWorkspaceName workspaceName;
    workspaceName = (IWorkspaceName)dataSet.FullName;

    // Creates RasterDatasetName object as output dataset name
    IRasterDatasetName rasDatasetName;
    rasDatasetName = new RasterDatasetNameClass();

    IDatasetName datasetName;
    datasetName = (IDatasetName)rasDatasetName;
    datasetName.WorkspaceName = workspaceName;
    datasetName.Name = "outSlope1";

    // Adds output dataset name to Op (force 10 execution path)
    IRasterOpBase rasOpBase;
    rasOpBase = (IRasterOpBase)surfaceOp;
    rasOpBase.AddOutputDatasetName(0, datasetName);

    // Omits Z factor
    System.Object zFactor = Type.Missing;

    // Runs the operation. Output                         
    IGeoDataset outSlope;
    outSlope = surfaceOp.Slope((IGeoDataset)elev1,
        esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref zFactor);
}
[VB.NET]
Public Sub SetOutputName()
    ' Gets an elevation raster from disk.
    ' NOTE: The method OpenRasterDataset was created previously in this document.
    ' It is not a standard ArcObject's function.
    Dim elev1 As IRasterDataset = OpenRasterDataset("C:\Spatial", "elevation")
    
    ' Creates the RasterSurfaceOp.
    Dim surfaceOp As ISurfaceOp = New RasterSurfaceOpClass()
    
    ' Sets the output name
    ' creates workspace name
    Dim wsFactory As IWorkspaceFactory
    wsFactory = New RasterWorkspaceFactoryClass()
    
    Dim ws As IWorkspace
    ws = wsFactory.OpenFromFile("C:\temp", 0)
    
    Dim dataSet As IDataset
    dataSet = CType(ws, IDataset)
    Dim workspaceName As IWorkspaceName
    workspaceName = CType(dataSet.FullName, IWorkspaceName)
    
    ' Creates RasterDatasetName object as output dataset name
    Dim rasDatasetName As IRasterDatasetName
    rasDatasetName = New RasterDatasetNameClass()
    
    Dim datasetName As IDatasetName
    datasetName = CType(rasDatasetName, IDatasetName)
    datasetName.WorkspaceName = workspaceName
    datasetName.Name = "outSlope1"
    
    ' Adds output dataset name to Op (force 10 execution path)
    Dim rasOpBase As IRasterOpBase
    rasOpBase = CType(surfaceOp, IRasterOpBase)
    rasOpBase.AddOutputDatasetName(0, datasetName)
    
    ' Omits Z factor
    Dim zFactor As System.Object = Type.Missing
    
    ' Runs the operation.
    Dim outSlope As IRaster
    outSlope = surfaceOp.Slope(elev1, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, zFactor)
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
ArcView: Spatial Analyst ArcView: Spatial Analyst
ArcEditor: Spatial Analyst ArcEditor: Spatial Analyst
ArcInfo: Spatial Analyst ArcInfo: Spatial Analyst