Select to view content in your preferred language

ArcObjects 10 - Query ordering not working (IQueryFilterDefinition.PostfixClause)

4012
6
09-28-2010 09:05 AM
BrentStevener
Deactivated User
I have a feature class (MyStreamsFeatureClass below) that I am trying to query features specifying an IQueryFilterDefinition.PostfixClause that specifies to order by a particular field. When I loop through these features after applying the search, the results are in the same order that they are in the shape file, as if the filter is not ordering them. What am I missing?

            'perform a query
            Dim MyQueryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilter
            MyQueryFilter.SubFields = "SEG_NAME, SEG_TYPE"

            'order clause, by name
            Dim MyQueryFilterDef As ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition = CType(MyQueryFilter, ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)
            MyQueryFilterDef.PostfixClause = "ORDER BY SEG_NAME"
            
            'get table from feature class
            Dim MyTable As ESRI.ArcGIS.Geodatabase.ITable = CType(MyStreamsFeatureClass, ESRI.ArcGIS.Geodatabase.ITable)
            
            'output the returned results of the query
            Dim MyCursor As ESRI.ArcGIS.Geodatabase.ICursor = MyTable.Search(MyQueryFilter, False)
            Dim MyRow As ESRI.ArcGIS.Geodatabase.IRow = MyCursor.NextRow
            Dim StreamsList As String = "Alphabetical Listing of Streams" & Environment.NewLine
            While MyRow IsNot Nothing
                StreamsList &= Convert.ToString(MyRow.Value(MyTable.FindField("SEG_NAME"))) & ", " & _
                               Convert.ToString(MyRow.Value(MyTable.FindField("SEG_TYPE"))) & Environment.NewLine
                MyRow = MyCursor.NextRow
            End While
            System.Windows.Forms.MessageBox.Show(StreamsList)
0 Kudos
6 Replies
JeffMatson
Frequent Contributor
Try obtaining your cursor using IQueryDef.Evaluate

See the section on "QueryDef cursors":
http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/bdb9558a-d78d-446c-a9d8-f35f9eb44a5b.htm#Que...
0 Kudos
BrentStevener
Deactivated User
But how do you specify an order? That is why I was using the PostfixClause...
0 Kudos
BrentStevener
Deactivated User
I think I found my answer. I think it is because I am just accessing these from a shapefile instead of a geodatabase.

"Please note, file geodatabase do not support the PostFixClause property, any specifications within the PostFixClause will be ignored."

I also only found this in the remarks section of the 9.2 documentation, which is another common problem of not having this information carried over. There are no remarks of this in the 10.0 reference for the same object, which complicates things further, unless that is not the real issue and doesn't pertain to 10.

I guess I can just add these items to my own .NET list and sort them from there, so no big deal.
0 Kudos
LanceShipman
Esri Regular Contributor
ORDER BY does work with the PostfixClause at ArcGIS 10.0 using a file geodatabase. The PostfixClause does NOT work with shapefiles. We will update the documentation to make this clear.
0 Kudos
NeilClemmons
Honored Contributor
You can use ITableSort to get a sorted cursor from the table.
0 Kudos
BrentStevener
Deactivated User
TableSort worked. I just need to be pointed in the right direction to the correct object. Thanks!
            'get table from feature class
            Dim MyTable As ESRI.ArcGIS.Geodatabase.ITable = CType(MyStreamsFeatureClass, ESRI.ArcGIS.Geodatabase.ITable)

            'create table sort 
            Dim MyTableSort As New ESRI.ArcGIS.Geodatabase.TableSort
            MyTableSort.Fields = "SEG_NAME, SEG_TYPE"
            MyTableSort.Ascending("SEG_NAME") = True
            MyTableSort.Table = MyTable
            'sort the table
            MyTableSort.Sort(Nothing)

            'output the returned results of the sort
            Dim MyCursor As ESRI.ArcGIS.Geodatabase.ICursor = MyTableSort.Rows
            Dim MyRow As ESRI.ArcGIS.Geodatabase.IRow = MyCursor.NextRow
            While MyRow IsNot Nothing
                System.Windows.Forms.Messagebox.Show(Convert.ToString(MyRow.Value(MyTable.FindField("SEG_NAME"))))
                MyRow = MyCursor.NextRow
            End While
0 Kudos