Maximum/Minimum attribute value

840
4
08-15-2010 10:20 PM
shivagugila
New Contributor III
Hi All,

Can anyone, please let me know if we can use 'queryfilter' to find max/min value in attribute table of a featureclass(Shape OR GDB). Any other suggestions/help ?

Regards,
Shiva
0 Kudos
4 Replies
ParitoshGupta
New Contributor III
Hi
   You can get a hint from following function to get maximum and minimum values for an attribute: -

Public Function RangeCalculator(ByVal PDF_Name As String, ByRef pFLayer As IFeatureLayer) As String

    Dim iMin, iMax As Integer
    Dim pTable As ITable
    Set pTable = pFLayer.FeatureClass
    Dim pCur As ICursor
    Dim pRow As IRow
    Dim iFEATID As Integer
    Dim iMAPPDFNO As Integer
    iFEATID = pTable.FindField("FEATID")
    iMAPPDFNO = pTable.FindField("MAPPDFNO")
    Dim pQF As IQueryFilter
    Set pQF = New QueryFilter
    pQF.WhereClause = "MAPPDFNO = '" & PDF_Name & "' AND FEATID <> ''"
    Set pCur = pTable.Search(pQF, False)
    Set pRow = pCur.NextRow
    iMin = CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2))
    iMax = CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2))

    Do While Not pRow Is Nothing
        If CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2)) < iMin Then
           iMin = CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2))
        End If
        If CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2)) > iMax Then
           iMax = CInt(Mid(pRow.value(iFEATID), 3, Len(pRow.value(iFEATID)) - 2))
        End If
        Set pRow = pCur.NextRow
    Loop
    If iMin = 0 Then
        RangeCalculator = iMin
    ElseIf iMax = 0 Then
        RangeCalculator = iMin
    Else
        RangeCalculator = iMin & "-" & iMax
    End If
   
    End Function
0 Kudos
NirYoscovitz
New Contributor III
Hi,

You can use IDataStatistics interface.
See the IDataStatistics Example in the Developer help.
In your case, use IStatisticsResults.Minimum & IStatisticsResults.Maximum properties instead of the Mean property proposed in the code.

Regards,
Nir
0 Kudos
shivagugila
New Contributor III
Hi Nir , Paritosh,

I some how got some sample with idatastats and got my code working. Anyway thanks a lot for ur replies.

Cheers,
Shiva.
0 Kudos
GregRieck
Occasional Contributor III
Hi,

You can use IDataStatistics interface.
See the IDataStatistics Example in the Developer help.
In your case, use IStatisticsResults.Minimum & IStatisticsResults.Maximum properties instead of the Mean property proposed in the code.

Regards,
Nir


This IDataStatistics Example helped me find the min and max:

http://forums.arcgis.com/threads/4826-Bind-attribute-field-to-drop-down-list

If you scroll down and look at response #13 it includes the following:
pCursor = pTableSort.Rows
Dim pQFilter As IQueryFilter
pQFilter = New QueryFilter
pQFilter.WhereClause = pQF

Dim pData As IDataStatistics
pData = New DataStatistics
pData.Field = fieldname
pCursor = pFeatureclass.Search(pQFilter, False)
'pCursor = pLayer
pData.Cursor = pCursor


While it doesn't specifically show the use of min and max you can still get to it from this example by using
double dMax = pData.Statistics.Maximum;
double dMin = pData.Statistics.Minimum;

The key thing here is that the pData.Field must be populated with the field you want to retrieve statistics on.

Hope, this helps someone else. I found this information to be somewhat lacking and felt it needed just that little extra to complete the thread. Who knows, I may search on this again sometime and be able to use my own comments.
0 Kudos