Select to view content in your preferred language

Getting Statistics on a field

2549
12
11-24-2017 05:48 AM
BrianBulla
Honored Contributor

In ArcObjects I would use Geodatabase.IDataStatistics to get stats on a field.  Does anyone know if an equivalent exists in ArcPro SDK??

Thanks,

0 Kudos
12 Replies
ColinZwicker
Esri Contributor

Brian,

ArcGIS Pro Core.Data has not exposed this functionality yet. We will look to do so in a future release.

Do you utilize the simple stats (count, min\max etc) or standard deviation?

Thanks,

Colin

0 Kudos
BrianBulla
Honored Contributor

Hi Colin,

Just simple stats is all I am looking for.

Thanks!

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Colin,

We are using UniqueValues, min, max. Please accelerate exposing of this functionality

0 Kudos
by Anonymous User
Not applicable

Hi Colin any word on when this might be exposed? Could do with an easy way of getting unique values from a field.

0 Kudos
ColinZwicker
Esri Contributor

Good timing

With the release of 2.2 check out:

ProConcepts Geodatabase · Esri/arcgis-pro-sdk Wiki · GitHub 

Edit: totally missed your unique value statement, let me check with the team.

Thanks,

Colin

0 Kudos
by Anonymous User
Not applicable

Thanks Colin, yes please confirm if unique vals can be retrieved

Cheers

0 Kudos
RichRuh
Esri Regular Contributor

Hi Luke,

Yes, it is possible to get the unique values of a field, but the way to do so isn't obvious.

As Colin pointed out, the key is to use the Table.CalculateStatistics() routine. This will allow you to generate statistics on one or more fields and includes the ability to execute a group by on these statistics. To get the unique values, you execute this code, passing in a "dummy" statistic to calculate.

In the example below, I build a list of unique values for the SUB_REGION field of a States table.

// Get field for Region


Field regionField = featureClassDefinition.GetFields().First(x => x.Name.Equals("SUB_REGION"));

// Create a "fake" StatisticsDescription object


StatisticsDescription statisticsDescription = new StatisticsDescription(regionField, new List<StatisticsFunction>() { StatisticsFunction.Count });

// Create a TableStatisticsDescription that will return unique Region values (and a

// count of how many rows have that value)


TableStatisticsDescription tableStatisticsDescription = new TableStatisticsDescription(new List<StatisticsDescription>() { statisticsDescription });


tableStatisticsDescription.GroupBy = new List<Field>(){ regionField };

// Generate the statistics (and list of unique values)


IReadOnlyList<TableStatisticsResult> results = statesFeatureClass.CalculateStatistics(tableStatisticsDescription);

// Table.CalculateStatistics() returns one TableStatisticsResult object for each unique

// GroupBy tuple.
// If you pass one field into the TableStatisticsDescription.GroupBy object, you'll get

// one TableStatisticsResult object for each unique value of that field


foreach(TableStatisticsResult result in results)
{
  // TableStatisticsResult.GroupBy returns one KeyValuePair<Field,object> for each field

  // in the TableStatisticsDescription.GroupBy list
  // If you only pass one field into that list, we only get one

  // KeyValuePair<Field,object>


  KeyValuePair<Field, object> groupByPair = result.GroupBy.First();

  // groupByPair.Field is the Field you passed into TableStatisticsDescription.GroupBy
  // groupByPair.Value is a unique value of that field


  string myFieldValue = (string) groupByPair.Value;
  Console.WriteLine(myFieldValue);
}

We'll take a look at providing a more obvious way this to do in a future version of ArcGIS Pro.

Let me know if this helps,

--Rich

DaveFullerton
Frequent Contributor

Did you ever provide a more obvious way to do this in the API, Rich?  I am running into some issues with this not working so well, for example, with type CIMXYEventDataConnection and when CIMSqlQueryDataConnection becomes CIMRelQueryTableDataConnection via joining to a local table (it does work with a join when the data are all in the file geodatabase).

0 Kudos
DaveFullerton
Frequent Contributor

@RichRuh @KoryKramer @ColinZwicker 

Repeating this question and tagging you guys in case you didn't see it before.

Did Esri ever provide a more obvious way to do this in the API, Rich?  I am running into some issues with this not working so well, for example, with type CIMXYEventDataConnection and when CIMSqlQueryDataConnection becomes CIMRelQueryTableDataConnection via joining to a local table (it does work with a join when the data are all in the file geodatabase).

0 Kudos