ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / UniqueValueRendererDefinition Class / ArcadeExpression Property
Example

In This Topic
    ArcadeExpression Property (UniqueValueRendererDefinition)
    In This Topic
    Gets or sets the arcade expression to be used to get unique values or combination of values from. This is required if ValueFields is null.
    Syntax
    public string ArcadeExpression {get; set;}
    Public Property ArcadeExpression As String
    Example
    Use Arcade expression to create Class Breaks
    var usaStatesLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
                     .FirstOrDefault(fl => fl.Name == "USA States");
      if (usaStatesLayer == null) return;
    
      //Note: Run within a QueuedTask
      //Create a color ramp from red to blue
      var colorRampForPopulation = ColorFactory.Instance.ConstructColorRamp(
            ColorRampAlgorithm.LinearContinuous,
            ColorFactory.Instance.RedRGB, ColorFactory.Instance.BlueRGB);
    
      //This Arcade expression categorizes the POP2000 field in the usaStates layer
      //into Low, Medium, and High values
      var arcade = @"if ($feature.POP2000 < 1000000)  
                       {return ""Low"";}" +
                   @"else if ($feature.POP2000 >= 100000 && $feature.POP2000 < 5000000) 
                      {return ""Medium""; }" +
                    @"else if ($feature.POP2000 >= 5000000) 
                      {return ""High"";}" +
                    @"else{return ""NA"";}";
      //Create the Arcade expression info
      CIMExpressionInfo arcadeExp = new CIMExpressionInfo();
      arcadeExp.Expression = arcade;
      arcadeExp.ReturnType = ExpressionReturnType.Default;
      arcadeExp.Title = "State Population Categorized";
      arcadeExp.Name = "USA States Population 2000";
    
      //Each population category is assigned a color from the color ramp and symbolized on the map
      // using a unique value renderer
      var uvr_desc = new UniqueValueRendererDefinition()
      {
        //ValueFields = new List<string> { "STATION" },
        ColorRamp = colorRampForPopulation,
        UseDefaultSymbol = true,
        ValuesLimit = 100,
        ArcadeExpression = arcadeExp.Expression
      };
      //Create the renderer and assign it to the layer
      var renderer = usaStatesLayer.CreateRenderer(uvr_desc);
      usaStatesLayer.SetRenderer(renderer);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also