I have a feature (point) with a field called 'Sequence'. The values in this column range from 1 to n. I can use IQueryFilter to get the first value, 1.
Dim pQry As IQueryFilter = New QueryFilter
pQry.WhereClause = """Seq"" = 1"
pCursor = pFC.Search(pQry, True)
If TypeOf pCursor Is IFeatureCursor Then
pFeat = pCursor.NextFeature
If TypeOf pFeat Is IFeature Then
fStartElevation = pFeat.Value(nElevationFld)
End If
End If
I cannot figure out how to use this method to select the MAX value, since it varies across features. Is it possible? I'm thinking I just need the correct syntax. I have tried a few variations of pQry.WhereClause = """MAX""Seq""" after doing some forum reading regarding aggregate functions in ArcGIS, but I haven't found a solution that works.
If this isn't possible (I figured it should operate similarly to SQL), is there another preferable method for performing this task? I am aware of Select By Attribute, but the syntax for this is tricky (examples online do not work in Arc10) and still requires the attribute table to be read.
EDIT: Here is a working solution using @George's suggestion based on IDataStatistics. I may just turn this into a small function that takes in a Featureclass and field name for the sake of re-usability.
pCursor = pFC.Search(Nothing, False)
If TypeOf pCursor Is IFeatureCursor Then
Dim pData As IDataStatistics = New DataStatisticsClass
pData.Field = "Sequence"
pData.Cursor = pCursor
Dim pStatResults As IStatisticsResults = pData.Statistics
Dim intMaxSequence As Integer = pStatResults.Maximum
End If
