Select to view content in your preferred language

Number format in colorizer

921
7
Jump to solution
07-16-2020 08:41 PM
by Anonymous User
Not applicable

Hi Guys,

Would like to check how to set number format in CIMRasterClassifyColorizer object.

Below is the code I am using and it does not seem to be working. Uma Harano‌?

  CIMRasterClassifyColorizer newColorizer = await this.SelectedRasterLayer.CreateColorizerAsync(classifyColorizerDef) as CIMRasterClassifyColorizer;

            var numberFormat = new CIMNumericFormat();
            numberFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
            numberFormat.RoundingValue = this.DecimalPlaces; //int 1 or above
            newColorizer.NumberFormat = numberFormat;
this.SelectedRasterLayer.SetColorizer(newColorizer);

When I check in Advance symbol option, it seems to be effective. but the labelling does not follow at all.

ArcGIS pro version I am using is 2.5.0.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Uma Harano‌,

Found out how to use NumberFormat class.

I have to instantiate first and Here is my complete code working in 2.5

var numberFormat = new CIMNumericFormat
            {
                RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals,
                RoundingValue = this.DecimalPlaces,//int 1 or above
                ZeroPad = true
            };
            
            newColorizer.NumberFormat = numberFormat;
            ArcGIS.Desktop.Internal.Core.NumberFormat<CIMNumberFormat> NumberFormat = new ArcGIS.Desktop.Internal.Core.NumberFormat<CIMNumberFormat>(numberFormat);
            foreach (var br in newColorizer.ClassBreaks)
            {
                var specialChar = br.Label.Substring(0, 1);
                //var value = NumberFormat.ValueToString(numberFormat, br.UpperBound);
                var value = NumberFormat.FormatNumber(br.UpperBound);
                br.Label = $"{specialChar}{value}";
            }

View solution in original post

0 Kudos
7 Replies
by Anonymous User
Not applicable

Hi Wolfgang Kaiser‌,

Any idea on that issue? or I miss some code to notify TOC UI change?

0 Kudos
UmaHarano
Esri Regular Contributor

Than,

This has been fixed in 2.6 (released today).

You can do something like this in code to fix the labels in the TOC to reflect your number format.

var numberFormat = new CIMNumericFormat
        {
          RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals,
          RoundingValue = 3,//int 1 or above
          ZeroPad = true
        };     
        rasterColorizer.NumberFormat = numberFormat;

        foreach (var br in rasterColorizer.ClassBreaks)
        {
          var specialChar = br.Label.Substring(0, 1);
          var value = NumberFormat.ValueToString(numberFormat, br.UpperBound);
          br.Label = $"{specialChar}{value}";
        }

Thanks

Uma

0 Kudos
by Anonymous User
Not applicable

Thank Uma Harano‌,

Is your sample code based on 2.6 or 2.5?

In 2.5, I can't find NumberFormat class, may I know which library you are using?

Best Regards,

Than

0 Kudos
by Anonymous User
Not applicable

Hi Uma Harano‌,

Found out how to use NumberFormat class.

I have to instantiate first and Here is my complete code working in 2.5

var numberFormat = new CIMNumericFormat
            {
                RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals,
                RoundingValue = this.DecimalPlaces,//int 1 or above
                ZeroPad = true
            };
            
            newColorizer.NumberFormat = numberFormat;
            ArcGIS.Desktop.Internal.Core.NumberFormat<CIMNumberFormat> NumberFormat = new ArcGIS.Desktop.Internal.Core.NumberFormat<CIMNumberFormat>(numberFormat);
            foreach (var br in newColorizer.ClassBreaks)
            {
                var specialChar = br.Label.Substring(0, 1);
                //var value = NumberFormat.ValueToString(numberFormat, br.UpperBound);
                var value = NumberFormat.FormatNumber(br.UpperBound);
                br.Label = $"{specialChar}{value}";
            }
0 Kudos
UmaHarano
Esri Regular Contributor

Hi Than,

Pro 2.6 was released yesterday. A new NumberFormat class in the Mapping assembly has been added to help with this.

Thanks

Uma

by Anonymous User
Not applicable

Thank Uma Harano‌,

So your sample code is based on 2.6. 

So in this thread there are two correct answer one for 2.6, one for 2.5 how to make both correct?

Best Regards,

Than

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Than

The code I provided is for 2.6.

In 2.5, when you make changes to the Number format of a renderer/colorizer using the API, it does not get updated in the TOC. This is a known issue in the 2.5 version of the Pro API. There is no fix for this in 2.5. I just checked out the code snippet you provided above - it is using an Internal class. It is recommended to not use Internal namespaces.

We have now fixed this in the 2.6 API using the new static class you can see in my code snippet.

Thanks

Uma

0 Kudos