EDN Code Exchange

Updated Sep 29, 2010
Samples

Access Raster Table

Description:

This sample shows how to get a value in a raster table given a field and an index.
Products:

Engine: VBA, VB6

Platforms: Windows

Minimum ArcGIS Release: 9.0

How to use:
  1. Call this procedure from VB6 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
End Sub