ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / FeatureLayer Class / CreateRenderer Method
A renderer definition object.
Example

In This Topic
    CreateRenderer Method (FeatureLayer)
    In This Topic
    Creates a renderer to a feature layer using a RendererDefinition. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function CreateRenderer( _
       ByVal rendererDefinition As RendererDefinition _
    ) As CIMRenderer

    Parameters

    rendererDefinition
    A renderer definition object.

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Cannot create renderer for layer.
    Remarks
    Use CanCreateRenderer to determine if the renderer is valid for the layer before creating it.
    Example
    How to apply a color ramp from a style to a feature layer
    public async Task ApplyColorRampAsync(FeatureLayer featureLayer, List<string> fields)
    {
    
        StyleProjectItem style =
            Project.Current.GetItems<StyleProjectItem>()
                .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        var colorRampList = await QueuedTask.Run(() => 
                    style.SearchColorRamps("Red-Gray (10 Classes)"));
        if (colorRampList == null || colorRampList.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
        await QueuedTask.Run(() =>
        {
            cimColorRamp = colorRampList[0].ColorRamp;
            var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
            renderer = featureLayer?.CreateRenderer(rendererDef);
            featureLayer?.SetRenderer(renderer);
        });
    
    }
    Set unique value renderer to the selected feature layer of the active map
    await QueuedTask.Run(() =>
    {
      var fields = new List<string> { "Type" }; //field to be used to retrieve unique values
      CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
          ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Pushpin);  //constructing a point symbol as a template symbol
      CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
      //constructing renderer definition for unique value renderer
      UniqueValueRendererDefinition uniqueValueRendererDef =
    new UniqueValueRendererDefinition(fields, symbolPointTemplate);
    
      //creating a unique value renderer
      var flyr = MapView.Active.GetSelectedLayers()[0] as FeatureLayer;
      CIMUniqueValueRenderer uniqueValueRenderer = flyr.CreateRenderer(uniqueValueRendererDef) as CIMUniqueValueRenderer;
    
      //setting the renderer to the feature layer
      flyr.SetRenderer(uniqueValueRenderer);
    });
    Create a Heatmap Renderer
    string colorBrewerSchemesName = "ArcGIS Colors";
    StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
    string colorRampName = "Heat Map 4 - Semitransparent";
    IList<ColorRampStyleItem> colorRampList = await QueuedTask.Run(() =>
    {
      return style.SearchColorRamps(colorRampName);
    });
    ColorRampStyleItem colorRamp = colorRampList[0];
    
    await QueuedTask.Run(() =>
    {
      //defining a heatmap renderer that uses values from Population field as the weights
      HeatMapRendererDefinition heatMapDef = new HeatMapRendererDefinition()
      {
        Radius = 20,
        WeightField = "Population",
        ColorRamp = colorRamp.ColorRamp,
        RendereringQuality = 8,
        UpperLabel = "High Density",
        LowerLabel = "Low Density"
      };
    
      FeatureLayer flyr = MapView.Active.Map.Layers[0] as FeatureLayer;
      CIMHeatMapRenderer heatMapRndr = flyr.CreateRenderer(heatMapDef) as CIMHeatMapRenderer;
      flyr.SetRenderer(heatMapRndr);
    });
    Create an Unclassed Renderer
    string colorBrewerSchemesName = "ArcGIS Colors";
    StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
    string colorRampName = "Heat Map 4 - Semitransparent";
    IList<ColorRampStyleItem> colorRampList = await QueuedTask.Run(() =>
    {
      return style.SearchColorRamps(colorRampName);
    });
    ColorRampStyleItem colorRamp = colorRampList[0];
    
    await QueuedTask.Run(() =>
    {
      CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Diamond);
      CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
      //defining an unclassed renderer with custom upper and lower stops
      //all features with value >= 5,000,000 will be drawn with the upper color from the color ramp
      //all features with value <= 50,000 will be drawn with the lower color from the color ramp
      UnclassedColorsRendererDefinition unclassRndrDef = new UnclassedColorsRendererDefinition
                            ("Population", symbolPointTemplate, colorRamp.ColorRamp, "Highest", "Lowest", 5000000, 50000)
      {
    
        //drawing features with null values with a different symbol
        ShowNullValues = true,
        NullValueLabel = "Unknown"
      };
      CIMPointSymbol nullSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 16.0, SimpleMarkerStyle.Circle);
      unclassRndrDef.NullValueSymbol = nullSym.MakeSymbolReference();
      FeatureLayer flyr = MapView.Active.Map.Layers[0] as FeatureLayer;
      CIMClassBreaksRenderer cbRndr = flyr.CreateRenderer(unclassRndrDef) as CIMClassBreaksRenderer;
      flyr.SetRenderer(cbRndr);
    });
    Create a Proportion Renderer with max and min symbol size capped
    string colorBrewerSchemesName = "ArcGIS Colors";
    StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
    string colorRampName = "Heat Map 4 - Semitransparent";
    IList<ColorRampStyleItem> colorRampList = await QueuedTask.Run(() =>
    {
      return style.SearchColorRamps(colorRampName);
    });
    ColorRampStyleItem colorRamp = colorRampList[0];
    
    await QueuedTask.Run(() =>
    {
      CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
      CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
      //minimum symbol size is capped to 4 point while the maximum symbol size is set to 50 point
      ProportionalRendererDefinition prDef = new ProportionalRendererDefinition("POPULATION", symbolPointTemplate, 4, 50, true)
      {
    
        //setting upper and lower size stops to stop symbols growing or shrinking beyond those thresholds
        UpperSizeStop = 5000000,  //features with values >= 5,000,000 will be drawn with maximum symbol size
        LowerSizeStop = 50000    //features with values <= 50,000 will be drawn with minimum symbol size
      };
      FeatureLayer flyr = MapView.Active.Map.Layers[0] as FeatureLayer;
      CIMProportionalRenderer propRndr = flyr.CreateRenderer(prDef) as CIMProportionalRenderer;
      flyr.SetRenderer(propRndr);
    
    });
    Create a True Proportion Renderer
    string colorBrewerSchemesName = "ArcGIS Colors";
    StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
    string colorRampName = "Heat Map 4 - Semitransparent";
    IList<ColorRampStyleItem> colorRampList = await QueuedTask.Run(() =>
    {
      return style.SearchColorRamps(colorRampName);
    });
    ColorRampStyleItem colorRamp = colorRampList[0];
    
    await QueuedTask.Run(() =>
    {
      CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
      CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
      //Defining proportional renderer where size of symbol will be same as its value in field used in the renderer.
      ProportionalRendererDefinition prDef = new ProportionalRendererDefinition("POPULATION", esriUnits.esriMeters, symbolPointTemplate, SymbolShapes.Square, ValueRepresentations.Radius);
    
      FeatureLayer flyr = MapView.Active.Map.Layers[0] as FeatureLayer;
      CIMProportionalRenderer propRndr = flyr.CreateRenderer(prDef) as CIMProportionalRenderer;
      flyr.SetRenderer(propRndr);
    
    });
    Defining a unique value renderer definition
    var uvrDef = new UniqueValueRendererDefinition()
    {
      ValueFields = new List<string> { "ACTYPE" },
      SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(
        ColorFactory.Instance.RedRGB, 10, SimpleMarkerStyle.Hexagon)
          .MakeSymbolReference(),
      ValuesLimit = 5
    };
    //Note: CreateRenderer can only create value classes based on
    //the current events it has received
    streamLayer.SetRenderer(streamLayer.CreateRenderer(uvrDef));
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also