ArcGIS Pro 3.4 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
    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

    ArcGIS Pro version: 3 or higher.
    See Also