How to use a raster classify renderer


This sample shows the basics of using RasterClassifyColorRampRenderer.

How to use

  1. Add a raster layer that has a table into to ArcMap and make sure it is first layer.
  2. Run the procedure in ArcMap Visual Basic Editor.
[VBA]
Sub UsingRasterClassifyColorRampRenderer()
    'Get Map
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap
    
    'Get raster input from layer
    Dim pRLayer As IRasterLayer
    Set pRLayer = pMap.Layer(0)
    Dim pRaster As IRaster
    Set pRaster = pRLayer.Raster
    
    'Create classfy renderer and QI RasterRenderer interface
    Dim pClassRen As IRasterClassifyColorRampRenderer
    Set pClassRen = New RasterClassifyColorRampRenderer
    Dim pRasRen As IRasterRenderer
    Set pRasRen = pClassRen
    
    'Set raster for the render and update
    Set pRasRen.Raster = pRaster
    pClassRen.ClassCount = 3
    pRasRen.Update
    
    'Create a color ramp to use
    Dim pRamp As IAlgorithmicColorRamp
    Set pRamp = New AlgorithmicColorRamp
    pRamp.Size = 3
    pRamp.CreateRamp True
    
    'Create symbol for the classes
    Dim pFSymbol As IFillSymbol
    Set pFSymbol = New SimpleFillSymbol
    
    'loop through the classes and apply the color and label
    Dim I As Integer
    For I = 0 To pClassRen.ClassCount - 1
        pFSymbol.Color = pRamp.Color(I)
        pClassRen.Symbol(I) = pFSymbol
        pClassRen.Label(I) = "Class" & CStr(I)
    Next I
    
    'Update the renderer and plug into layer
    pRasRen.Update
    Set pRLayer.Renderer = pClassRen
    pMxDoc.ActiveView.Refresh
    pMxDoc.UpdateContents
    
    'Release memeory
    Set pMxDoc = Nothing
    Set pMap = Nothing
    Set pRLayer = Nothing
    Set pRaster = Nothing
    Set pRasRen = Nothing
    Set pClassRen = Nothing
    Set pRamp = Nothing
    Set pFSymbol = Nothing
End Sub