Get ClassBreaks in ArcGIS Pro SDK

169
1
09-19-2023 09:00 AM
Sai_PhaneendraPoludasu2
New Contributor III

I am working on migrating some ArcObjects code to ArcGIS Pro SDK .NET where we are extracting the natural class breaks using class break renderer sampling with a table histogram.

I could not find any references which I can use to convert/migrate the below mentioned code. Any help on this much appreciated.

 

public double[] GetClassBreaks(string tableName, string fieldName, int noOfClasses) {
  object values;
  object frequencies;

  ITable table = getTable(strTable, false);
  ITableHistogram tableHistogram = new TableHistogramClass();
  IClassBreaksRenderer classBreakRenderer = new ClassBreaksRendererClass();
  IDataSampling rendererSampling = classBreakRenderer as IDataSampling;
  rendererSampling.MaxSampleSize = 10000000;
  tableHistogram.Table = table;
  tableHistogram.Field = fieldName;
  tableHistogram.Sampling = rendererSampling;
  IHistogram histogram = (IHistogram) tableHistogram;
  histogram.GetHistogram(out values, out frequencies);
  IClassifyGEN classify = new NaturalBreaksClass();
  classify.Classify(values, frequencies, ref noOfClasses);
  //return the breaks in an array of type double
  return (double[]) classify.ClassBreaks;

  return breaks;
}

 

Thanks

0 Kudos
1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

In ArcGIS Pro you don't have to define the class breaks manually anymore.  Instead, you simply specify the Classification Method.   In the snippet below ClassificationMethod.NaturalBreaks is used.   

The Geodatabase API provides some functionality to get table statistics like standard deviation.  You can find some information here:  ProConcepts Geodatabase · Esri/arcgis-pro-sdk Wiki (github.com)

 

internal static Task CBRendererGraduatedSymbols()
{
  //Check feature layer name
  //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
  var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");
  if (featureLayer == null)
  {
    MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
    return Task.FromResult(0);
  }
  return QueuedTask.Run(() =>
    {
        GraduatedSymbolsRendererDefinition gsDef = new GraduatedSymbolsRendererDefinition()
        {                   
            ClassificationField = SDKHelpers.GetNumericField(featureLayer), //getting the first numeric field
            ClassificationMethod = ClassificationMethod.NaturalBreaks,
            SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(76,230,0)).MakeSymbolReference(),
            MinimumSymbolSize = 4,
            MaximumSymbolSize = 50,
            BreakCount = 5,
            ColorRamp = SDKHelpers.GetColorRamp(), //getting a color ramp
        };
        CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gsDef);
        featureLayer?.SetRenderer(renderer);
    });
}

 

 

You can find more about Renderers here:  arcgis-pro-sdk-community-samples/Map-Authoring/Renderer at master · Esri/arcgis-pro-sdk-community-sa...