How to open a file based raster dataset


This sample shows how to open a raster dataset from a file.

How to use

  1. Add this function to your project.
  2. Call this function from your code, passing in appropriate arguments.
[VBA]
Public Function OpenRasterDataset(sDir As String, sFile As String) As IRasterDataset
    
    'Open the raster dataset with the given name.
    'sDir is the directory the file resides
    'sFile is the filename
    
    Dim pWsFact As IWorkspaceFactory
    Dim pWs As IRasterWorkspace
    Dim pRasterDataset As IRasterDataset
    
    
    'Open the workspace
    Set pWsFact = New RasterWorkspaceFactory
    Set pWs = pWsFact.OpenFromFile(sDir, 0)
    
    
    'Open the raster dataset
    Set pRasterDataset = pWs.OpenRasterDataset(sFile)
    
    
    'Return
    Set OpenRasterDataset = pRasterDataset
    
    Set pWsFact = Nothing
    Set pWs = Nothing
    Set pRasterDataset = Nothing
    
End Function