Using RasterClassifyColorRampRenderer


This sample shows the basic steps of using RasterClassifyColorRampRenderer.

How to use:
  1. Make sure the first layer of ArcMap is raster layer.
  2. Run the procedure in ArcMap Visual Basic Editor. The layer will be rendered accordingly.
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
     ' 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
    Set pRLayer.Renderer = pClassRen
     ' 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