Select to view content in your preferred language

UniqueValueRendererDefinition reversed order

291
1
Jump to solution
04-15-2025 11:10 AM
JonathanDewalt
Regular Contributor

Hello. I am trying to create a uniquevaluerender on a date field.  the code below works just fine however the final product is always sorted with the newest date on the bottom, I need it the other way around.  This is what it is creating.

JonathanDewalt_0-1744740381900.png

this is what i need.

JonathanDewalt_1-1744740461648.png

It doesn't seem to matter what order the records are in the featureclass, same results.   Any suggestions on how to sort the uniqurenderer in descending order?

 

await QueuedTask.Run(async () =>
{


StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
if (style == null) return;
var colorRampList = await QueuedTask.Run(() =>
style.SearchColorRamps("Yellow-Orange-Red (Continuous)"));
if (colorRampList == null || colorRampList.Count == 0) return;
CIMColorRamp cimColorRamp = null;
CIMRenderer renderer = null;

var fields = new List<string> { rmg.AlbertaWildfireTools.Core.Models.AlbertaSchema.IncidentFields.Default(AlbertaWildfireTools.Core.Models.AlbertaSchema.IncidentFields.FieldNames.field_FirProgressionProgDate )};

await QueuedTask.Run(() =>
{
cimColorRamp = colorRampList[0].ColorRamp;
var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp,null,false);

renderer = featureLayer?.CreateRenderer(rendererDef);

featureLayer?.SetRenderer(renderer);

});


});

0 Kudos
1 Solution

Accepted Solutions
JonathanDewalt
Regular Contributor

This did the trick after creating renderer.

 if (renderer is CIMUniqueValueRenderer uniqueValueRenderer) { // Sort the classes in descending order var groups = uniqueValueRenderer.Groups; if (groups != null && groups.Length > 0) { // Assuming the first group contains the date classes var classes = groups[0].Classes; if (classes != null && classes.Length > 0) { // Sort classes by label in descending order Array.Sort(classes, (a, b) => string.Compare(b.Label, a.Label, StringComparison.Ordinal)); groups[0].Classes = classes; } } }

 

View solution in original post

0 Kudos
1 Reply
JonathanDewalt
Regular Contributor

This did the trick after creating renderer.

 if (renderer is CIMUniqueValueRenderer uniqueValueRenderer) { // Sort the classes in descending order var groups = uniqueValueRenderer.Groups; if (groups != null && groups.Length > 0) { // Assuming the first group contains the date classes var classes = groups[0].Classes; if (classes != null && classes.Length > 0) { // Sort classes by label in descending order Array.Sort(classes, (a, b) => string.Compare(b.Label, a.Label, StringComparison.Ordinal)); groups[0].Classes = classes; } } }

 

0 Kudos