How to access a raster dataset


Summary
A raster dataset can be stored as file based or in a geodatabase. This topic shows how to access a file-based raster dataset and a geodatabase raster dataset.


Accessing a file-based raster dataset

To access a file-based raster dataset, use IRasterWorkspace and perform the following steps:
  1. Open a raster file workspace.
  2. Open a file raster dataset.
See the following code example:
[C#]
static IRasterDataset OpenFileRasterDataset(string folderName, string datasetName)
{
    //Open a raster file workspace.
    IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
    IRasterWorkspace rasterWorkspace = (IRasterWorkspace)
        workspaceFactory.OpenFromFile(folderName, 0);

    //Open a file raster dataset. 
    IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(datasetName);
    return rasterDataset;
}
[VB.NET]
Public Function OpenFileRasterDataset(ByVal folderName As String, ByVal datasetName As String) As IRasterDataset
    'Open a raster file workspace.
    Dim workspaceFactory As IWorkspaceFactory = New RasterWorkspaceFactoryClass()
    Dim rasterWorkspace As IRasterWorkspace = CType(workspaceFactory.OpenFromFile(folderName, 0), IRasterWorkspace)
    
    'Open a file raster dataset.
    Dim rasterDataset As IRasterDataset = rasterWorkspace.OpenRasterDataset(datasetName)
    
    Return rasterDataset
End Function

Accessing a geodatabase raster dataset

To access a raster dataset in a geodatabase, first open a geodatabase workspace (see Accessing raster workspaces for details). Then use the IRasterWorkspaceEx interface as shown in the following code example:
[C#]
static IRasterDataset OpenGDBRasterDataset(IRasterWorkspaceEx rasterWorkspaceEx,
    string datasetName)
{
    //Open a raster dataset in a geodatabase (PGDB, FGDB, or ArcSDE).
    return rasterWorkspaceEx.OpenRasterDataset(datasetName);
}
[VB.NET]
Public Function OpenGDBRasterDataset(ByVal rasterWorkspaceEx As IRasterWorkspaceEx, ByVal datasetName As String) As IRasterDataset
    'Open a raster dataset in a geodatabase (PGDB, FGDB, or ArcSDE).
    Return rasterWorkspaceEx.OpenRasterDataset(datasetName)
End Function


See Also:

How to access a raster catalog
Accessing a raster dataset in a raster catalog




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 ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine