How to add a raster layer to a map


This sample shows how to create a raster layer and add it to a map.

How to use

  1. In ArcMap, call this procedure from VBA.
[VBA]
Sub AddRasterLayer(pRasterDs As IRasterDataset)
    'pRasterDs represets a RasterDataset from a raster workspace, an access workspace or an sde workspace.
    
    'Create a raster layer. Use CreateFromRaster method when creating from a Raster.
    Dim pRasterLy As IRasterLayer
    Set pRasterLy = New RasterLayer
    pRasterLy.CreateFromDataset pRasterDs
    
    'Add the raster layer to ArcMap
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    pMxDoc.FocusMap.AddLayer pRasterLy
    pMxDoc.ActiveView.Refresh
End Sub