In ArcObjects I would use Geodatabase.IDataStatistics to get stats on a field. Does anyone know if an equivalent exists in ArcPro SDK??
Thanks,
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
Hi Colin,
Just simple stats is all I am looking for.
Thanks!
Hi Colin,
We are using UniqueValues, min, max. Please accelerate exposing of this functionality
Hi Colin any word on when this might be exposed? Could do with an easy way of getting unique values from a field.
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
Thanks Colin, yes please confirm if unique vals can be retrieved
Cheers
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
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).
@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).