English

How To: Use the IInterpolationOp Krige method in Spatial Analyst Extension

Summary

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

Procedure

 

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

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.
Code:
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 on 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.