ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / FeatureLayer Class / SetRenderer Method / SetRenderer(CIMRenderer,FeatureRendererTarget) Method
Your custom renderer that will be used to draw features of the feature layer.
A FeatureRendererTarget indicating the intended usage of the resulting renderer.
Example

In This Topic
    SetRenderer(CIMRenderer,FeatureRendererTarget) Method
    In This Topic
    Specifies the feature layer's renderer object which determines how the layer draws. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Sub SetRenderer( _
       ByVal renderer As CIMRenderer, _
       ByVal featureRendererTarget As FeatureRendererTarget _
    ) 

    Parameters

    renderer
    Your custom renderer that will be used to draw features of the feature layer.
    featureRendererTarget
    A FeatureRendererTarget indicating the intended usage of the resulting renderer.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Renderer cannot be of type CIMHeatMapRenderer
    Renderer cannot be of type CIMDotDensityRenderer
    The provided renderer cannot be used as a {0} renderer for this layer
    This feature layer does not support tracks
    Remarks
    Intended for use with StreamLayer. For non-stream layer types use FeatureRendererTarget.Default. Passing FeatureRendererTarget.PreviousObservations or FeatureRendererTarget.TrackLines for a non-track aware layer (feature or stream) will throw a System.InvalidOperationException. If the feature layer is a member of a SubtypeGroupLayer, the renderer argument passed cannot be of type CIMHeatMapRenderer or you will get a System.ArgumentException. If the feature layer is a member of a SubtypeGroupLayer and is in the 3D category of the table of contents in a 3D view, the renderer argument passed cannot be of type CIMDotDensityRenderer or you will get a System.ArgumentException. Use the IsSubtypeLayer property to determine if the feature layer is a member of a SubtypeGroupLayer. Use the SceneLayerType property to determine if the feature layer is in 3D category of the table of contents.
    Example
    How to set symbol for a feature layer symbolized with simple renderer
    public Task SetFeatureLayerSymbolAsync(FeatureLayer ftrLayer, CIMSymbol symbolToApply)
    {
      if (ftrLayer == null || symbolToApply == null)
        throw new System.ArgumentNullException();
    
      return QueuedTask.Run(() =>
      {
    
        //Get simple renderer from the feature layer
        CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;
        if (currentRenderer == null)
          return;
    
        //Set symbol's real world setting to be the same as that of the feature layer
        symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
    
        //Update the symbol of the current simple renderer
        currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
        //Update the feature layer renderer
        ftrLayer.SetRenderer(currentRenderer);
      });
    }
    
    How to apply a symbol from style to a feature layer
    public Task SetFeatureLayerSymbolFromStyleItemAsync(
               FeatureLayer ftrLayer, SymbolStyleItem symbolItem)
    {
      if (ftrLayer == null || symbolItem == null)
        throw new System.ArgumentNullException();
    
      return QueuedTask.Run(() =>
      {
        //Get simple renderer from the feature layer
        CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;
        if (currentRenderer == null)
          return;
        //Get symbol from the SymbolStyleItem
        CIMSymbol symbol = symbolItem.Symbol;
    
        //Set symbol's real world setting to be the same as that of the feature layer
        symbol.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
    
        //Update the symbol of the current simple renderer
        currentRenderer.Symbol = symbol.MakeSymbolReference();
        //Update the feature layer renderer
        ftrLayer.SetRenderer(currentRenderer);
      });
    }
    
    How to apply a point symbol from a style to a feature layer
      // var map = MapView.Active.Map;
      // if (map == null)
      //        return;
      // var pointFeatureLayer =
      //       map.GetLayersAsFlattenedList()
      //          .OfType<FeatureLayer>()
      //         .Where(fl => fl.ShapeType == esriGeometryType.esriGeometryPoint);
      //   await ApplySymbolToFeatureLayerAsync(pointFeatureLayer.FirstOrDefault(), "Fire Station");
    
      public Task ApplySymbolToFeatureLayerAsync(FeatureLayer featureLayer, string symbolName)
      {
        return QueuedTask.Run(async () =>
        {
          //Get the ArcGIS 2D System style from the Project
          var arcGIS2DStyle =
    Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    
          //Search for the symbolName style items within the ArcGIS 2D style project item.
          var items = await QueuedTask.Run(() =>
          arcGIS2DStyle.SearchSymbols(StyleItemType.PointSymbol, symbolName));
    
          //Gets the CIMSymbol
          CIMSymbol symbol = items.FirstOrDefault().Symbol;
    
          //Get the renderer of the point feature layer
          CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
    
          //Set symbol's real world setting to be the same as that of the feature layer
          symbol.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
    
          //Apply the symbol to the feature layer's current renderer
          renderer.Symbol = symbol.MakeSymbolReference();
    
          //Appy the renderer to the feature layer
          featureLayer.SetRenderer(renderer);
        });
      }
    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);
        });
    
    }
    Modify renderer using Arcade
    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
    if (lyr == null) return;
    QueuedTask.Run(() =>
    {
      // GetRenderer from Layer (assumes it is a unique value renderer)
      var uvRenderer = lyr.GetRenderer() as CIMUniqueValueRenderer;
      if (uvRenderer == null) return;
      //layer has STATE_NAME field
      //community sample Data\Admin\AdminSample.aprx
      string expression = "if ($view.scale > 21000000) { return $feature.STATE_NAME } else { return 'All' }";
      CIMExpressionInfo updatedExpressionInfo = new CIMExpressionInfo
      {
        Expression = expression,
        Title = "Custom" // can be any string used for UI purpose.
      };
      //set the renderer's expression
      uvRenderer.ValueExpressionInfo = updatedExpressionInfo;
    
      //SetRenderer on Layer
      lyr.SetRenderer(uvRenderer);
    });
    Modify label expression using Arcade
    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
    if (lyr == null) return;
    QueuedTask.Run(() =>
    {
      //Get the layer's definition
      //community sample Data\Admin\AdminSample.aprx
      var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
      if (lyrDefn == null) return;
      //Get the label classes - we need the first one
      var listLabelClasses = lyrDefn.LabelClasses.ToList();
      var theLabelClass = listLabelClasses.FirstOrDefault();
      //set the label class Expression to use the Arcade expression
      theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;";
      //Set the label definition back to the layer.
      lyr.SetDefinition(lyrDefn);
    });
    
    Setting a unique value renderer for previous observations
    //The layer must be track aware and spatial
    if (streamLayer.TrackType != TrackType.Spatial)
      return;
    //Must be on QueuedTask!
    //Define unique value classes same as we do for current observations
    //or use "CreateRenderer(...)" to assign them automatically
    CIMUniqueValueClass uvcB727Prev = new CIMUniqueValueClass()
    {
      Values = new CIMUniqueValue[] { new CIMUniqueValue() {
        FieldValues = new string[] { "B727" } } },
      Visible = true,
      Label = "Boeing 727",
      Symbol = SymbolFactory.Instance.ConstructPointSymbol(
        CIMColor.CreateRGBColor(255, 0, 0), 4, SimpleMarkerStyle.Hexagon)
        .MakeSymbolReference()
    };
    
    CIMUniqueValueClass uvcD9Prev = new CIMUniqueValueClass()
    {
      Values = new CIMUniqueValue[] { new CIMUniqueValue() {
        FieldValues = new string[] { "DC9" } } },
      Visible = true,
      Label = "DC 9",
      Symbol = SymbolFactory.Instance.ConstructPointSymbol(
        CIMColor.CreateRGBColor(0, 255, 0), 4, SimpleMarkerStyle.Hexagon)
        .MakeSymbolReference()
    };
    
    CIMUniqueValueGroup uvGrpPrev = new CIMUniqueValueGroup()
    {
      Classes = new CIMUniqueValueClass[] { uvcB727Prev, uvcD9Prev }
    };
    
    var UVrndrPrev = new CIMUniqueValueRenderer()
    {
      Fields = new string[] { "ACTYPE" },
      Groups = new CIMUniqueValueGroup[] { uvGrpPrev },
      UseDefaultSymbol = true,
      DefaultLabel = "Others",
      DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(
        CIMColor.CreateRGBColor(185, 185, 185), 4, SimpleMarkerStyle.Hexagon)
        .MakeSymbolReference()
    };
            
    streamLayer.SetRenderer(UVrndr, FeatureRendererTarget.PreviousObservations);
    Setting a simple renderer to draw track lines
    //The layer must be track aware and spatial
    if (streamLayer.TrackType != TrackType.Spatial)
      return;
    //Must be on QueuedTask!
    //Note: only a simple renderer with solid line symbol is supported for track 
    //line renderer
    var trackRenderer = new SimpleRendererDefinition()
    {
      SymbolTemplate = SymbolFactory.Instance.ConstructLineSymbol(
          ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.Solid)
            .MakeSymbolReference()
    };
    streamLayer.SetRenderer(
         streamLayer.CreateRenderer(trackRenderer), 
           FeatureRendererTarget.TrackLines);
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also