Summarize field Command

259
6
05-15-2014 08:09 PM
Highlighted
Occasional Contributor II
Hi all,

I created an Addin to summarize a field using FeatureCount() method and add the result table into a list view. the purpose of the tool is to find duplicate atttributes. The code bellow works fine but it takes about 1 minute to return the result when quering multiple features (more than 5000 features for example). I am wondering if there is a sql statement to use such as Select fieldName, Count(FieldName) from table Group by FieldName, or is there a way to call the summarize field command in ArcMap? Also, attached is a screenshot of the tool with results.[ATTACH=CONFIG]33859[/ATTACH]



  'define datastat to query unique values
            Dim pDataStats As New DataStatisticsClass()
            'define data collection
            Dim pEnum As IEnumerator
            pDataStats.Field = selectedFieldName
            pDataStats.Cursor = fCursor
            pEnum = pDataStats.UniqueValues

            Dim dataStatResult As IStatisticsResults = pDataStats.Statistics
           
            pEnum.Reset()



            Do While pEnum.MoveNext

                'Add unique feature in the first column

                newlist = ListViewDataresult.Items.Add(pEnum.Current)

                'define the whereclause
                Dim whereclause As String = String.Format("{0} = '{1}'", pDataStats.Field, pEnum.Current)

                Dim queryFilter As IQueryFilter = New QueryFilterClass()
               
                queryFilter.WhereClause = whereclause

                Try
                    'Adding the count of features in the second column
                    newlist.SubItems.Add(fclass.FeatureCount(queryFilter))
                Catch ex As Exception
                    MessageBox.Show("Ooops, FieldCount Error: " & ex.Message)
                End Try

               
               
            Loop



Reply
0 Kudos
6 Replies
Highlighted
MVP Frequent Contributor
Move this line:

Dim queryFilter As IQueryFilter = New QueryFilterClass()


above this line

Do While pEnum.MoveNext


This should improve performance as you do not need to keep creating this object. You only need to create it once and update the whereclause.
Reply
0 Kudos
Highlighted
Occasional Contributor II
Thank you for your reply, I moved the line above the DoWhile as you mentioned but still taking a while about 1minute. The layer I am testing this tool on has about 6000 features.
Reply
0 Kudos
Highlighted
MVP Frequent Contributor
You could try putting an attribute index on your field selectedFieldName or abandon the approach you are using and call the summary statistics tool, may be writing the output to a temporary in_memory workspace?
Reply
0 Kudos
Highlighted
Occasional Contributor II
Thank you Hornbydd ,

Well, I am looking for that different approach. How do you call the summarize  field command? what is the syntax for it? I do not seem to find it anywhere on the forum. I do think that would be the best way to do it but just don't know how!
Reply
0 Kudos
Highlighted
MVP Frequent Contributor
I'm suggesting you call the summary statistics geo-processing tool. There are several ways to do this one method is discussed here but I prefer this approach where you create an array of parameters and feed that into the chosen tool. It's what ever you find easiest.
Reply
0 Kudos
Highlighted
Occasional Contributor III
What about Frequency Tool,It will get the count.
You can get the result in InMemory Table and populate it to your list.
You can run the tool from Arcmap and check its performance and output structue.
Sample:
  private ITable RunFrequencyTool(ITable inputTable, string inputField)
        {
            try
            {
                ESRI.ArcGIS.AnalysisTools.Frequency FrequencyTool = new ESRI.ArcGIS.AnalysisTools.Frequency();
                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result;
                FrequencyTool.in_table = inputTable;
                FrequencyTool.frequency_fields = inputField;
                FrequencyTool.out_table = "in_memory\\Result";
                Result = RunTool(FrequencyTool, null);
                return GetTablefromResult(Result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return null;
            }
        }


  private ESRI.ArcGIS.Geodatabase.ITable  GetTablefromResult(ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult result)
        {
            ESRI.ArcGIS.Geodatabase.IGPValue GPVal;
            string OutputTableName;
            ESRI.ArcGIS.Geoprocessing.IGPUtilities3 GPUtil = new ESRI.ArcGIS.Geoprocessing.GPUtilities() as ESRI.ArcGIS.Geoprocessing.IGPUtilities3;
            ESRI.ArcGIS.Geodatabase.ITable  pOutputTable;
            try
            {
                GPVal = result.GetOutput(0);
                OutputTableName = GPVal.GetAsText();
                pOutputTable = GPUtil.OpenTableFromString(OutputTableName);
                return pOutputTable;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Reply
0 Kudos