ArcGIS Pro SDK - Unique Values Grouping

155
1
Jump to solution
07-17-2020 03:10 PM
NikholaiO_Hara
Occasional Contributor

Hello,

I'm using the ArcGIS Pro SDK to modify the symbology for some of our layers. Everything is going good except one thing is evading me. I have a feature layer that utilizes unique values. I have managed to symbolize my layer to match the screenshot below. The last thing i need to to figure out is how I can group the symbols to be under one symbol instead of 7 different ones. I want to take the 'WIA with Rules' and group them into one symbol. Anyone have any ideas on how to do this?

I'm assuming it has something to do with the CIMUniqueValues FieldValues or with the CIMUniqueValueGroup, but i cant figure it out.

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Nikholai,

To group the values using the API, you can do this.

1. Create your Unique Value renderer the way you have been doing.

2. To add "grouping" you have to work with the CIM (Cartographic Information Model). 

   * Get the Layer's definition as CIMFeatureLayer.

   * Access the Renderer from the definition.

   * Modify the "Groups" property on the Renderer.

Below is the code snippet I used on a layer. It had two fields that I symbolized on. I then grouped the features with the "Rock" attributes.

        //Get the Layer's CIM Defintion
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Access the renderer
var renderer = lyrDefn.Renderer as CIMUniqueValueRenderer;

var symbol1 = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB);
var symbol2 = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB);

//Create the info needed for the Grouping
var groupRiverValues = new List<CIMUniqueValue>
{
new CIMUniqueValue { FieldValues = new string[] {"River", "5"} }
};

var groupRockValues = new List<CIMUniqueValue>
{
new CIMUniqueValue { FieldValues = new string[] {"Rock", "2"} },
new CIMUniqueValue { FieldValues = new string[] {"Rock", "3"} },
};
//This is the part where you create the grouping classes
var uniqueValueClasses = new List<CIMUniqueValueClass>
{
new CIMUniqueValueClass{Symbol = symbol1.MakeSymbolReference() , Editable = false, Patch = PatchShape.Default,Label = "River,5", Values = groupRiverValues.ToArray(), Visible = true},
new CIMUniqueValueClass() { Symbol = symbol2.MakeSymbolReference(), Editable = true, Patch = PatchShape.Default, Label = "Rock,3; Rock,4",Values = groupRockValues.ToArray(), Visible = true}

};
//Create the "Groups"
var groups = new List<CIMUniqueValueGroup>
{
new CIMUniqueValueGroup {Classes = uniqueValueClasses.ToArray(), Heading = "DisplayField,SubDisplay" }
};
//Set the Groups property on the renderer object
renderer.Groups = groups.ToArray();
//Important: Set the modified layer definition back
featureLayer.SetDefinition(lyrDefn);

Let me know if you run into issues.

Thanks

Uma

View solution in original post

Reply
0 Kudos
1 Reply
UmaHarano
Esri Regular Contributor

Hi Nikholai,

To group the values using the API, you can do this.

1. Create your Unique Value renderer the way you have been doing.

2. To add "grouping" you have to work with the CIM (Cartographic Information Model). 

   * Get the Layer's definition as CIMFeatureLayer.

   * Access the Renderer from the definition.

   * Modify the "Groups" property on the Renderer.

Below is the code snippet I used on a layer. It had two fields that I symbolized on. I then grouped the features with the "Rock" attributes.

        //Get the Layer's CIM Defintion
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Access the renderer
var renderer = lyrDefn.Renderer as CIMUniqueValueRenderer;

var symbol1 = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB);
var symbol2 = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB);

//Create the info needed for the Grouping
var groupRiverValues = new List<CIMUniqueValue>
{
new CIMUniqueValue { FieldValues = new string[] {"River", "5"} }
};

var groupRockValues = new List<CIMUniqueValue>
{
new CIMUniqueValue { FieldValues = new string[] {"Rock", "2"} },
new CIMUniqueValue { FieldValues = new string[] {"Rock", "3"} },
};
//This is the part where you create the grouping classes
var uniqueValueClasses = new List<CIMUniqueValueClass>
{
new CIMUniqueValueClass{Symbol = symbol1.MakeSymbolReference() , Editable = false, Patch = PatchShape.Default,Label = "River,5", Values = groupRiverValues.ToArray(), Visible = true},
new CIMUniqueValueClass() { Symbol = symbol2.MakeSymbolReference(), Editable = true, Patch = PatchShape.Default, Label = "Rock,3; Rock,4",Values = groupRockValues.ToArray(), Visible = true}

};
//Create the "Groups"
var groups = new List<CIMUniqueValueGroup>
{
new CIMUniqueValueGroup {Classes = uniqueValueClasses.ToArray(), Heading = "DisplayField,SubDisplay" }
};
//Set the Groups property on the renderer object
renderer.Groups = groups.ToArray();
//Important: Set the modified layer definition back
featureLayer.SetDefinition(lyrDefn);

Let me know if you run into issues.

Thanks

Uma

View solution in original post

Reply
0 Kudos