English

How To: Return the data source name of an SDE raster layer

Summary

In ArcMap, you can right-click on a layer to display its properties. The source tab displays the source name of the layer even when the layer has been renamed in the Table of Contents (TOC). This article illustrates how to return the source name for a raster layer using ArcObjects.

Procedure

 

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
    Note:
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. Copy the following code into the UIButtonControl's click event.
     
    Code:
    Dim pApp As IApplication
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pLayer As ILayer
    Dim pRasterLayer As IRasterLayer
    
    Dim pRaster As IRaster
    Dim pRasterBandColl As IRasterBandCollection
    Dim pEnumRasterBand As IEnumRasterBand
    Dim pRasterBand As IRasterBand
    Dim pRasterDataset As IRasterDataset
    Dim pDataset As IDataset
    
    Set pApp = Application
    Set pMxDoc = pApp.Document
    Set pMap = pMxDoc.FocusMap
    Set pLayer = pMap.Layer(0)
    Set pRasterLayer = pLayer  ' QI
    
    Debug.Print "LayerName: " & pLayer.Name
    Set pRaster = pRasterLayer.Raster
    Set pRasterBandColl = pRaster  ' QI
    
    Set pEnumRasterBand = pRasterBandColl.Bands
    pEnumRasterBand.Reset
    
    'Set pRasterBand = pRasterBandColl.BandByName("Band_1")
    Set pRasterBand = pEnumRasterBand.Next
    
    Do Until pRasterBand Is Nothing
       
        Set pRasterDataset = pRasterBand.RasterDataset
        Set pDataset = pRasterDataset  ' QI
        Debug.Print "Dataset.Name: " & pDataset.Name
        
        Set pRasterBand = pEnumRasterBand.Next
    Loop
  5. Click AddData to load an SDE raster into the TOC.
  6. Right-click on the layer and select the General tab. Provide a new layer name then click OK.
  7. Click on the button to run the code.
  8. Open the Visual Basic Editor. In ArcMap, select Tools > Macros > Visual Basic Editor.
  9. From the View menu click Immediate Window to review the values returned by the code.