I'm trying to count rows by unique values for a given FeatureClass. I'm using DataStatistics to get the unique values for a specific column for a given FeatureClass.
This seems to be (very) slow with big shapefiles (> 200k of features) - is there a faster way to determine unique values?
The second step of the process (using QueryFilter in combination with FeatureClass.FeatureCount()) seems fast enough although I would be glad if im pointed to a better solution.
public static Dictionary<string, int> CountUniquesStatistic(ITable table, string fldName)
{
Dictionary<string, int> uniqueValuesDictionary = new Dictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
DataStatistics dataStatistics = new DataStatistics();
dataStatistics.Field = fldName;
dataStatistics.Cursor = table.Search(null, false);
IEnumerator uniqueValues = dataStatistics.UniqueValues;
while (uniqueValues.MoveNext())
{
object current = uniqueValues.Current;
uniqueValuesDictionary[current.ToString()] = 0;
}
foreach (string key in uniqueValuesDictionary.Keys.ToList())
{
IQueryFilter queryFilter = new QueryFilter();
queryFilter.WhereClause = string.Format("{0} = '{1}'", fldName, key);
uniqueValuesDictionary[key] = table.RowCount(queryFilter);
}
return uniqueValuesDictionary;
}
