Access Raster Table

Created:4/4/2001
Description:

This sample shows how to get values of a given field from raster table.

How to use:
  1. Call this procedure from VB or VBA.
Sub AccessValueOfRasterTable(pRaster As IRaster, sFieldName As String, RowIndex As Integer)
     ' pRaster: input raster
    ' sFieldName: field name in the raster table
    ' RowIndex: row index in the table
    
    ' Get Rasterband
     Dim pRasterCol As IRasterBandCollection
    Set pRasterCol = pRaster
    Dim pBand As IRasterBand
    Set pBand = pRasterCol.Item(0)

     ' Get the raster table
     Dim pTable As ITable
    Dim TableExist As Boolean
    pBand.HasTable TableExist
    If Not TableExist Then Exit Sub
    Set pTable = pBand.AttributeTable
    
     ' Get field index
     Dim FieldIndex As Integer
    FieldIndex = pTable.FindField(sFieldName)

     ' Get the value
     Dim ValueResult As Variant
    Dim pRow As IRow
    Set pRow = pTable.GetRow(RowIndex)
    ValueResult = pRow.Value(FieldIndex)

     ' Here is the result
     MsgBox ValueResult
    Exit Sub
ERH:
    MsgBox Err.Description
End Sub