Reverse Sort method located in Symbology

540
3
09-17-2012 07:01 AM
AkhilParujanwala
New Contributor III
I am trying to find the Reverse Sort function using ArcObjects.
As you can see in the image below, ArcMap has the function to Reverse Sort when I right click on the words "all other values".
By performing the Reverse Sort function, the values column is sorted in a correct manner.
Right now my values section appears to be in a mixed order, 1,2,3,0,4,8. But with Reverse Sort, it will sort the values 0,1,2,3,4,8, which is what I want.

Can anyone tell me what interface and object I would need to get access to this method? Or is there an alternative.
I am using C#, VS 2010 and ArcGIS 10.

[ATTACH=CONFIG]17724[/ATTACH]

Thanks in advance.
0 Kudos
3 Replies
AkhilParujanwala
New Contributor III
Any suggestions?
Or alternative ways to move the uniquevalues up and down so I can sort them manually if needed?

Kindly advise, thanks.
0 Kudos
PeterYurkosky1
Occasional Contributor
The sorting behavior is part of the dialog, and is not exposed through ArcObjects. You can get the values in the renderer via IUniqueValueRenderer, sort them yourself, and add them in the correct order to the renderer.
0 Kudos
AkhilParujanwala
New Contributor III
Thank you pyurkosk.

I am going to quickly outline what I did so that in the future others who may try to do this can get an idea of how I did this.

In order to sort unique value in a order of your chosing, you may follow these steps.
1) RemoveAllValues - because you will add them one by one with their unique symbology
2) Create an enumeration for the layer's subtypes - you may not being using subtypes, in which you can simply create a list of the classes you want
3) Using linq to sort the list in ascending order by the value field - you can use descending if needed
4) Loop and add each class to the unique value renderer with a symbol or unique
5 Loop through each newly added unique value and set the label to the description - if this last step is not done, then your label will be the same value of the "value"
6) Assign the renderer to the geo feature layer

I am giving my code below to help others, but this is specific to my needs, but it can be easily adjusted for anyone's needs.

[PHP]
           // Removes all classes from the layer's symbology.
            pUniqueValueRenderer.RemoveAllValues(); 
         
            // Create an enumeration for the layer's subtypes.
            IFeatureClass pFeatureClass = (IFeatureClass)pGeoFeatureLayer.FeatureClass;
            ISubtypes pSubtypes = (ISubtypes)pFeatureClass;
            IEnumSubtype enumSubtype;
            int subtypeCode;
            string subtypeName;
            List<ENTSubtypeClassSymbology> subtypeClassList = new List<ENTSubtypeClassSymbology>();

            // Loops through the subtype enumeration and store the value and description
            // into a list.
            if (pSubtypes.HasSubtype)
            {
                enumSubtype = pSubtypes.Subtypes;
                subtypeName = enumSubtype.Next(out subtypeCode);
                ENTSubtypeClassSymbology aSubtypeClass = new ENTSubtypeClassSymbology();
                aSubtypeClass.Value = subtypeCode.ToString();
                aSubtypeClass.Description = subtypeName;
                subtypeClassList.Add(aSubtypeClass);

                while (subtypeName != null)
                {
                    subtypeName = enumSubtype.Next(out subtypeCode);
                    ENTSubtypeClassSymbology aNewSubtypeClass = new ENTSubtypeClassSymbology();
                    aNewSubtypeClass.Value = subtypeCode.ToString();
                    aNewSubtypeClass.Description = subtypeName;
                    if (aNewSubtypeClass.Description != null)
                        subtypeClassList.Add(aNewSubtypeClass);
                }
            }
            else
            {
                throw new Exception("Subtypes/classes have not been defined");
            }

            // Sort the list of subtypes in ascending order.
            var linqSort = (from ENTSubtypeClassSymbology c in subtypeClassList
                            orderby c.Value ascending
                            select c) as List<ENTSubtypeClassSymbology>;

            var sortedSubtypeClassList = subtypeClassList.OrderBy(c => c.Value).ToList();

            // Create a symbol for the unique values.
            stdole.IFontDisp pFontDisp;
            pFontDisp = new stdole.StdFontClass() as stdole.IFontDisp;
            pFontDisp.Name = "ESRI Default Marker";

            ICharacterMarkerSymbol pCharacterMarkerSymbol;
            pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
            pCharacterMarkerSymbol.Size = 8;
            pCharacterMarkerSymbol.Angle = 0;
            pCharacterMarkerSymbol.Font = pFontDisp;
            pCharacterMarkerSymbol.CharacterIndex = 34;
            pCharacterMarkerSymbol.Color = Utilities.CreateRGBColor(0, 0, 0);

            // Add each subtype to the unique value renderer.
            foreach (ENTSubtypeClassSymbology subtypeClass in sortedSubtypeClassList)
            {
                pUniqueValueRenderer.AddValue(subtypeClass.Value, "SUBTYPE", pCharacterMarkerSymbol as ISymbol);
            }

            // Loop through each added unique value and set the label to the description
            // of the corresponding subtype value.
            for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 2; i++)
            {
                string value = pUniqueValueRenderer.get_Value(i);
                ENTSubtypeClassSymbology aSubtypeClass = sortedSubtypeClassList.Find(delegate(ENTSubtypeClassSymbology theSubtypeClass) { return theSubtypeClass.Value == i.ToString(); });
                pUniqueValueRenderer.set_Label(i.ToString(), aSubtypeClass.Description);
            }

            pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer;
[/PHP]

If anyone has questions please ask, I will do my best to answer.
0 Kudos