This sample shows how to use IIdentify interface with raster layer.
How to use
- Add a command button to any toolbar in ArcMap.
- Paste the example into VBA and associate it with the command button that you just add.
Private Sub UIToolControl1_Select()
Dim pMxDoc As IMxDocument
Dim pApp As IMxApplication
Set pMxDoc = ThisDocument
Set pApp = Application
'Get raster layer and IQ IIdentify interface
Dim pRasterLy As IRasterLayer
Dim pIdentify As IIdentify
Set pRasterLy = pMxDoc.FocusMap.Layer(0)
Set pIdentify = pRasterLy
'Convert x and y to map units
Dim pPoint As IPoint
Set pPoint = pApp.Display.DisplayTransformation(X, Y)
'Identify on the raster layer
Dim pIDArray As IArray
Set pIDArray = pIdentify.Identify(pPoint)
'Get the raster information
Dim pRasObj As IRasterIdentifyObj
Dim PixelValue As String
If Not pIDArray Is Nothing Then
Set pRasObj = pIDArray.Element(0)
PixelValue = pRasObj.Name
MsgBox PixelValue
End If
End Sub