AnsweredAssumed Answered

How to create an UniqueValueRenderer?

Question asked by htudosieesri-ca-esridist Employee on Sep 29, 2016
Latest reply on Sep 30, 2016 by cmacleod-esristaff

I would prefer the method for ArcGIS Desktop described here:

Symbols and renderers—ArcGIS Runtime SDK for .NET | ArcGIS for Developers 

But I cannot make it work in ArcGis PRO.


Instead I use the following code:

var uniqueValueRendererDef = GetUniqueValueRendererDef();
var uniqueValueRenderer = (CIMUniqueValueRenderer)deltaLayer.CreateRenderer(uniqueValueRendererDef);
var classes = uniqueValueRenderer.Groups[0].Classes;
uniqueValueRendererDef = GetUniqueValueRendererDef(classes);
uniqueValueRenderer = (CIMUniqueValueRenderer)deltaLayer.CreateRenderer(uniqueValueRendererDef);

private UniqueValueRendererDefinition GetUniqueValueRendererDef(CIMUniqueValueClass[] classes = null)
    string[] fields = { Model.DbFieldOperation.Key }; //field to be used to retrieve unique values

    CIMMultiLayerSymbol symbol = null;

    switch (DeltaLayer.ShapeType)
        case esriGeometryType.esriGeometryPolygon:
            symbol = SymbolFactory.ConstructPolygonSymbol(
                            ColorFactory.GreyRGB, SimpleFillStyle.Solid, new CIMSolidStroke()
                                Width = 3.0,
                                Color = //CIMColor.CreateRGBColor(0, 0, 0, 127)

    var symbolTemplate = symbol.MakeSymbolReference();

    var colorRamp = new CIMFixedColorRamp();
    if (classes == null)
        colorRamp.Colors = new[] { ColorFactory.RedRGB, ColorFactory.GreenRGB };
        var colors = new List();
        foreach (var cls in classes)
            switch (cls.Label)
                case "DELETE":
                    colors.Add(DeltaLayer.ShapeType == esriGeometryType.esriGeometryPolygon
                        ? ColorFactory.CreateRGBColor(255, 0, 0, 128) : ColorFactory.RedRGB);
        colorRamp.Colors = colors.ToArray();

    var uniqueValueRendererDef = new UniqueValueRendererDefinition(fields, symbolTemplate, colorRamp);

    return uniqueValueRendererDef;


Explanation: The first call to GetUniqueValueRendererDef() in line 2 is to obtain the unique values (in line 4.)

The second call in line 5 produces the desired ColorRamp. The efect was described in my question:

How to use ColorFactory to produce transparent colors for a ColorRamp? 

I cannot simply produce an universal color ramp with 3 (or more) colors because the renter allocates for the second and subsequent values random colors from the ramp when the ramp contains more colors than unique values!

This is inconvenient - I would call it a bug!


Now, the real problem in this post:

For Polynomial Layers I need transparent symbols - this I have already described in the above question.

However, in line 21 I have also asked for a stroke (solid black - although my first preference was transparent as well) 3 units tick.

Not only the stroke does not come, but neither can be added with the symbol editor!

Look at the effect when using a SimpleFillStyle.Vertical filling (line 21)

The cyan rectangle is the selected polygon, but there are 2 polygons there and without stroke line it is impossible to make the difference. Obviously, any king of filling won't replace the transparency on the symbol, but missing strokes makes thinks even worse!

The Format Polygon Symbol dialog shoes:

The solid stroke checkbox came unchecked - why?

When manually checking it, I can see what I want!

(Much better!)