This document is archived and information here might be outdated.  Recommended version.


How to create a raster classify renderer (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Displaying raster data > How to create a raster classify renderer

How to create a raster classify renderer


Creating a raster classify renderer

Do the following steps to create a raster classify renderer:
  1. Create the classify renderer.
  2. Set up the renderer properties.
  3. Set the color ramp for the symbology.
  4. Create the symbol for the classes.

    See the following code example:
[C#]
public IRasterRenderer ClassifyRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset
    rasterDataset)
{
    try
    {
        //Create the classify renderer.
        IRasterClassifyColorRampRenderer classifyRenderer=new
            RasterClassifyColorRampRendererClass();
        IRasterRenderer rasterRenderer=(IRasterRenderer)classifyRenderer;

        //Set up the renderer properties.
        IRaster raster=rasterDataset.CreateDefaultRaster();
        rasterRenderer.Raster=raster;
        classifyRenderer.ClassCount=3;
        rasterRenderer.Update();

        //Set the color ramp for the symbology.
        IAlgorithmicColorRamp colorRamp=new AlgorithmicColorRampClass();
        colorRamp.Size=3;
        bool createColorRamp;
        colorRamp.CreateRamp(out createColorRamp);

        //Create the symbol for the classes.
        IFillSymbol fillSymbol=new SimpleFillSymbolClass();
        for (int i=0; i < classifyRenderer.ClassCount; i++)
        {
            fillSymbol.Color=colorRamp.get_Color(i);
            classifyRenderer.set_Symbol(i, (ISymbol)fillSymbol);
            classifyRenderer.set_Label(i, Convert.ToString(i));
        }
        return rasterRenderer;
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
        return null;
    }
}
[VB.NET]
Public Function ClassifyRenderer(ByVal rasterDataset As ESRI.ArcGIS.Geodatabase.IRasterDataset) As IRasterRenderer
    Try
    'Create the classify renderer.
    Dim classifyRenderer As IRasterClassifyColorRampRenderer=New RasterClassifyColorRampRendererClass()
    Dim rasterRenderer As IRasterRenderer=CType(classifyRenderer, IRasterRenderer)
    
    'Set up the renderer properties.
    Dim raster As IRaster=rasterDataset.CreateDefaultRaster()
    rasterRenderer.Raster=raster
    classifyRenderer.ClassCount=3
    rasterRenderer.Update()
    
    'Set the color ramp for the symbology.
    Dim colorRamp As IAlgorithmicColorRamp=New AlgorithmicColorRampClass()
    colorRamp.Size=3
    Dim createColorRamp As Boolean
    colorRamp.CreateRamp( createColorRamp)
    
    'Create the symbol for the classes.
    Dim fillSymbol As IFillSymbol=New SimpleFillSymbolClass()
    Dim i As Integer
    For i=0 To classifyRenderer.ClassCount - 1 Step i + 1
        fillSymbol.Color=colorRamp.get_Color(i)
        classifyRenderer.set_Symbol(i, CType(fillSymbol, ISymbol))
        classifyRenderer.set_Label(i, Convert.ToString(i))
    Next
    Return rasterRenderer
    Catch ex As Exception
    System.Diagnostics.Debug.WriteLine(ex.Message)
    Return Nothing
    End Try
End Function


See Also:

How to create a raster layer




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Advanced
Engine Developer Kit Engine