How to access a raster colormap


This sample shows how to access the colormap of a raster dataset.

How to use

  1. Call this procedure from VBA.
[VBA]
Public Function AccessRasterColorMap(pRasterDs As IRasterDataset) As IRasterColormap
    'pRasterDs: a raster dataset from file or geodatabase
    
    Dim pRasterBandCol As IRasterBandCollection
    Dim pRasterBand As IRasterBand
    Dim pRasterColormap As IRasterColormap
    Dim HasColormap As Boolean
    
    Set pRasterBandCol = pRasterDs
    
    If pRasterBandCol.Count = 1 Then
        Set pRasterBand = pRasterBandCol.Item(0)
        pRasterBand.HasColormap HasColormap
        If HasColormap = True Then
            Set pRasterColormap = pRasterBand.Colormap
        Else
            Set pRasterColormap = Nothing
        End If
    Else
        pRasterColormap = Nothing
    End If
    
    Set AccessRasterColorMap = pRasterColormap
End Function