Unique value renderer - specifying values?

1574
3
07-17-2018 08:51 AM
by Anonymous User
Not applicable

I'm looking to programmatically construct a unique value renderer to match the following symbology I've applyed to a layer in ArcGIS Pro:

In my example, my layer has a field "Operator" with 100 unique values. I want one symbology class (blue) for a couple of these values "BP PLC" and "CNOOC LIMITED", and one symbology class (red) for all other values. So it appears like this in the ToC:

How can I achieve this using the Pro SDK, if at all?  I've looked at snippets but can only find code for a basic unique value renderer with a colour ramp. I can't see how to specify which individual values have which symbol class.

Many thanks

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi Luke

The images did not come thorough, but I think I get what you are trying to do with the UniqueValueRenderer. Here is a code snippet that will symbolize fields with specific symbols based on values, instead of using a color ramp.

You have to modify the CIMUniqueValueRenderer to get what you are trying to do.

        internal static Task UniqueValueRenderer(FeatureLayer featureLayer)
        {
            return QueuedTask.Run(() =>
            {
                //The goal is to construct the CIMUniqueValueRenderer which will be applied to the feature layer.
                // To do this, the following are the objects we need to set the renderer up with the fields and symbols.
                // As a reference, this is the USCities dataset. Snippet will create a unique value renderer that applies 
                // specific symbols to all the cities in California and Alabama.  The rest of the cities will use a default symbol.
                
                // First create a "CIMUniqueValueClass" for the cities in Alabama.
                List<CIMUniqueValue> listUniqueValuesAlabama = new List<CIMUniqueValue> { new CIMUniqueValue { FieldValues = new string[] { "Alabama" } } };
                CIMUniqueValueClass alabamaUniqueValueClass = new CIMUniqueValueClass
                {
                    Editable = true,
                    Label = "Alabama",
                    Patch = PatchShape.Default,
                    Symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB).MakeSymbolReference(),
                    Visible = true,
                    Values = listUniqueValuesAlabama.ToArray()

                };
                // Create a "CIMUniqueValueClass" for the cities in California.
                List<CIMUniqueValue> listUniqueValuescalifornia = new List<CIMUniqueValue> { new CIMUniqueValue { FieldValues = new string[] { "California" } } };
                CIMUniqueValueClass californiaUniqueValueClass = new CIMUniqueValueClass
                {
                    Editable = true,
                    Label = "California",
                    Patch = PatchShape.Default,
                    Symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB).MakeSymbolReference(),
                    Visible = true,
                    Values = listUniqueValuescalifornia.ToArray()
                };
                //Create a list of the above two CIMUniqueValueClasses
                List<CIMUniqueValueClass> listUniqueValueClasses = new List<CIMUniqueValueClass>
                {
                        alabamaUniqueValueClass, californiaUniqueValueClass
                };
                //Create a list of CIMUniqueValueGroup
                CIMUniqueValueGroup uvg = new CIMUniqueValueGroup
                {
                    Classes = listUniqueValueClasses.ToArray(),
                };
                List<CIMUniqueValueGroup> listUniqueValueGroups = new List<CIMUniqueValueGroup> { uvg };
                //Create the CIMUniqueValueRenderer
                CIMUniqueValueRenderer uvr = new CIMUniqueValueRenderer
                {
                    UseDefaultSymbol = true,
                    DefaultLabel = "all other values",
                    DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreyRGB).MakeSymbolReference(),
                    Groups = listUniqueValueGroups.ToArray(),
                    Fields = new string[] { "STATE_NAME" }
                };
                //Set the feature layer's renderer.
                featureLayer.SetRenderer(uvr);
            });
        }

Thanks

Uma

by Anonymous User
Not applicable

Thank you Uma, this looks like what I need! Will give this a go.

0 Kudos
by Anonymous User
Not applicable

Working nicely, thanks again.

0 Kudos