ArcGIS Pro 3.7 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
    {
        List<string> fields = new List<string>() { "Field1" };
        //Note: Needs QueuedTask to run
        StyleProjectItem styleToUse =
          Project.Current.GetItems<StyleProjectItem>()
              .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        //Note: Needs QueuedTask to run
        var colorRampListFound = styleToUse.SearchColorRamps("Red-Gray (10 Classes)");
        if (colorRampListFound == null || colorRampListFound.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
    
        cimColorRamp = colorRampListFound[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
    {
        //field to be used to retrieve unique values
        //Note: Run within a QueuedTask
        var fields = new List<string> { "Type" };
        //constructing a point symbol as a template symbol
        CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
            ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Pushpin);
        CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
        //constructing renderer definition for unique value renderer
        UniqueValueRendererDefinition uniqueValueRendererDef =
      new UniqueValueRendererDefinition(fields, symbolPointTemplate);
    
        //creating a unique value renderer
        CIMUniqueValueRenderer uniqueValueRenderer = featureLayer.CreateRenderer(uniqueValueRendererDef) as CIMUniqueValueRenderer;
    
        //setting the renderer to the feature layer
        featureLayer.SetRenderer(uniqueValueRenderer);
    }
    Create a Heatmap Renderer
    {
        string colorBrewerSchemesName = "ArcGIS Colors";
        //Get the style project item that contains the color ramps
        //Refer to the Initialize region for an example of how to get a style item
        //and the color ramp from it.
        //Note: Run within a QueuedTask
        //defining a heatmap renderer that uses values from Population field as the weights
        HeatMapRendererDefinition heatMapDef = new HeatMapRendererDefinition()
        {
            Radius = 20,
            WeightField = "Population",
            ColorRamp = colorRamp,
            RendereringQuality = 8,
            UpperLabel = "High Density",
            LowerLabel = "Low Density"
        };
        CIMHeatMapRenderer heatMapRndr = featureLayer.CreateRenderer(heatMapDef) as CIMHeatMapRenderer;
        featureLayer.SetRenderer(heatMapRndr);
    }
    Create an unclassed Renderer
    {
        string colorBrewerSchemesName = "ArcGIS Colors";
        //Get the style project item that contains the color ramps
        //Refer to the Initialize region for an example of how to get a style item
        //Note: Run within a QueuedTask
        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, "Highest", "Lowest", 5000000, 50000)
        {
    
            //drawing features with null values with a different symbol
            ShowNullValues = true,
            NullValueLabel = "Unknown"
        };
        // Create a point symbol for null values
        CIMPointSymbol nullSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 16.0, SimpleMarkerStyle.Circle);
        unclassRndrDef.NullValueSymbol = nullSym.MakeSymbolReference();
        //Create the unclassed renderer using the definition
        CIMClassBreaksRenderer cbRndr = featureLayer.CreateRenderer(unclassRndrDef) as CIMClassBreaksRenderer;
        //Set the renderer to the feature layer
        featureLayer.SetRenderer(cbRndr);
    }
    Create a Proportion Renderer with max and min symbol size capped
    {
        string colorBrewerSchemesName = "ArcGIS Colors";
        //Get the style project item that contains the color ramps
        //Refer to the Initialize region for an example of how to get a style item
        //Note: Run within a QueuedTask
        //Creating a point symbol to be used as a template symbol for the proportional renderer
        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
        //Creating a proportional renderer definition that uses the "Population" field
        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
        };
        // Create a proportional renderer using the definition
        CIMProportionalRenderer propRndr = featureLayer.CreateRenderer(prDef) as CIMProportionalRenderer;
        // Set the renderer to the feature layer
        featureLayer.SetRenderer(propRndr);
    }
    Create a True Proportion Renderer
    {
        string colorBrewerSchemesName = "ArcGIS Colors";
        //Get the style project item that contains the color ramps
        //Refer to the Initialize region for an example of how to get a style item
        //Note: Run within a QueuedTask
        //Creating a point symbol to be used as a template symbol for the proportional renderer
        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);
        //Create a Proportional renderer using the definition
        CIMProportionalRenderer propRndr = featureLayer.CreateRenderer(prDef) as CIMProportionalRenderer;
        // Set the renderer to the feature layer
        featureLayer.SetRenderer(propRndr);
    }
    Defining a unique value renderer definition
    {
      // Note: call within QueuedTask.Run()
      {
        streamLayer = null;
        //https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer
    
        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 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also