How to change the renderer for table based raster catalogs


A table based raster catalog is displayed in ArcMap using the default renderer of the first raster dataset in the raster catalog table. The two samples allow you to modify the default renderer of the raster catalog by using information from any raster dataset in the raster catalog table.

How to use

  1. Call this subroutine from VBA.
  2. For how to use, see comments in each subroutine .
[VBA]
Sub ChangeCatalogRenderer1()
    'Add one of the raster dataset from raster catalog into
    'ArcMap. Make sure the raster dataset layer is the first layer in TOC and raster catalog is
    'the second layer. Change the renderer of the raster layer to the desired
    'one. After running this subroutine, the renderer of the raster layer will be applied
    'to the raster catalog layer
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    ' Get raster layer
    Dim pRasLyr As IRasterLayer
    Set pRasLyr = pMxDoc.FocusMap.Layer(0)
    
    ' Get raster renderer from the raster layer
    Dim pRasRen As IRasterRenderer
    Set pRasRen = pRasLyr.Renderer
    
    ' Apply the raster renderer to the catalog layer
    Dim pCatLyr As IRasterCatalogLayer
    Set pCatLyr = pMxDoc.FocusMap.Layer(1)
    Set pCatLyr.Renderer = pRasRen
    pMxDoc.ActiveView.Refresh
End Sub

Sub ChangeCatalogRenderer2()
    'Add a 8.x version raster catalog into ArcMap and select it, then run this subrotine.
    'This subroutine cutomizes a raster stretch renderer using
    'statistics from one of the raster dataset in the raster catalog
    'table (the second), then apply the customized renderer to the
    'raster catalog layer.
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pLy As ILayer
    Dim pCatLy As IRasterCatalogLayer
    
    ' Get Catalog layer
    Set pLy = pMxDoc.SelectedLayer
    If Not TypeOf pLy Is IRasterCatalogLayer Then
        MsgBox "Please select an image catalog layer"
        Exit Sub
    End If
    Set pCatLy = pLy
    
    ' Get the second dataset (or any other)
    Dim pRDS As IRasterDataset
    Dim pCatTable As IRasterCatalogTable
    Set pCatTable = pCatLy.CatalogTable
    Set pRDS = pCatTable.RasterDataset(1)
    Dim pRaster As IRaster
    Set pRaster = pRDS.CreateDefaultRaster
    
    'Create render
    Dim pStretch As IRasterStretchColorRampRenderer
    Set pStretch = New RasterStretchColorRampRenderer
    Dim pRasRen As IRasterRenderer
    Set pRasRen = pStretch
    
    ' Connect the render to the raster
    Set pRasRen.Raster = pRaster
    pRasRen.Update
    
    'Define two colors
    Dim pFromColor As IColor
    Dim pToColor As IColor
    Set pFromColor = New RgbColor
    pFromColor.RGB = RGB(255, 0, 0)
    Set pToColor = New RgbColor
    pToColor.RGB = RGB(0, 255, 0)
    
    ' Create color ramp
    Dim pRamp As IAlgorithmicColorRamp
    Set pRamp = New AlgorithmicColorRamp
    pRamp.Size = 255
    pRamp.FromColor = pFromColor
    pRamp.ToColor = pToColor
    pRamp.CreateRamp True
    
    ' Plug this colorramp into renderer and select a band
    pStretch.BandIndex = 0
    pStretch.ColorRamp = pRamp
    
    ' Update the renderer with new settings and plug into layer
    pRasRen.Update
    Set pCatLy.Renderer = pStretch
    pMxDoc.ActiveView.Refresh
    pMxDoc.UpdateContents
End Sub