Creating a raster classify renderer
Do the following steps to create a raster classify renderer:
- Create the classify renderer.
- Set up the renderer properties.
- Set the color ramp for the symbology.
- Create the symbol for the classes.
See the following code example:
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 layerTo 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):
ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Display ESRI.ArcGIS.Geometry ESRI.ArcGIS.DataSourcesGDB ESRI.ArcGIS.Geodatabase ESRI.ArcGIS.DataSourcesRaster ESRI.ArcGIS.Carto
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Basic | ArcGIS for Desktop Advanced |
Engine Developer Kit | Engine |