Use the IInterpolationOp Krige method in Spatial Analyst Extension

Last Published: April 25, 2020


This article pertains to ArcGIS versions 8.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

This VBA code sample illustrates to use IInterpolationOp's Krige method.

Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward


  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy the below code into the UIButtonControl's click event.

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pMap As IMap
Set pMap = pMxDoc.ActiveView

Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(0)

Dim pFClass As IFeatureClass
Set pFClass = pFLayer.FeatureClass

Dim pInput As IGeoDataset
Set pInput = pFClass

Dim pFeatureClassDescriptor As IFeatureClassDescriptor
Set pFeatureClassDescriptor = New FeatureClassDescriptor

''Change the string value ("height") to a field name in the featureclass.
pFeatureClassDescriptor.Create pFClass, Nothing, "height"

Dim pAV As IActiveView
Set pAV = pMap
Dim pREnv As IEnvelope
Set pREnv = pAV.Extent


' Create RasterInterpolationOp object
Dim pIntOp As IInterpolationOp
Set pIntOp = New RasterInterpolationOp

' Set cell size for output raster. The extent of the output raster is
' defualted to as same as input. The output working directory uses Default
Dim pEnv As IRasterAnalysisEnvironment
Set pEnv = pIntOp

pEnv.SetCellSize esriRasterEnvValue, pREnv.Width / 250
pEnv.SetExtent esriRasterEnvValue, pREnv

' Create raster radius using variable distance
Dim pRadius As IRasterRadius
Set pRadius = New RasterRadius
pRadius.SetVariable 12

' Use FeatureClassDescriptor as an input to the IInterpolationOp
' Perform the interpolation
Dim pOutRaster As IRaster
Set pOutRaster = pIntOp.Krige(pFeatureClassDescriptor, esriGeoAnalysisUniversal1SemiVariogram, pRadius, True)

Dim strData As String
''' The output GRID will be named "MyRaster"
strData = "C:\temp\MyRaster"
Call createFileFromRaster(pOutRaster, strData)
  1. Copy the below code into the same module as the UIButtonControl.
Sub createFileFromRaster(pRaster As IRaster, OutFN As String)

Dim pRasterBandC As IRasterBandCollection
Set pRasterBandC = pRaster
pRasterBandC.SaveAs OutFN, Nothing, "GRID"

End Sub
  1. Click AddData to load a point FeatureClass into ArcMap.
  2. Modify the line of code that calls the Create method on IFeatureClassDescriptor.
    Provide the name of the field that contains the Z-values to be interpolated.
  3. Click Tools and select References. Click Browse to navigate to the ESRI Spatial Analyst Shared Object Library and check it on.
  4. Click the button to run the code.

Article ID:000005375

  • ArcMap 8 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options