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


How to access a raster dataset (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > Accessing raster datasets > How to access a raster dataset (ArcObjects .NET 10.6 SDK)

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.

In this topic


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