How to interpolate using RasterInterpolationOp and IGeoAnalysisSemivariogram


This sample code demonstrates how to interpolate, using kriging, a point shapefile/feature class to a raster by using the GeoAnalysisSemiVariogram object.

How to use

  1. Start ArcMap.
  2. Add a point shapefile/feature class that has a value field into ArcMap.
  3. Make sure that the Spatial Analyst Extension is turned on.
  4. Paste the following code into VBA.
  5. Change the field name and specify a cell size to fit your data.
  6. Change the semi-variogram input parameters.
  7. Set a reference to the ESRI GeoAnalyst Object Library.
  8. Run the sub from the Macros dialog.
[VBA]
Sub GeoAnalysisSemiVariogram()
    'Get the focused map from MapDocument
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    
    'Get the feature class from first layer
    Dim pFLayer As IFeatureLayer
    Set pFLayer = pMap.Layer(0)
    Dim pFClass As IFeatureClass
    Set pFClass = pFLayer.FeatureClass
    
    'Specify the fieldname
    Dim sFieldName As String
    sFieldName = "height"
    
    'Create FeatureClassDescriptor using a value field
    Dim pFCDescriptor As IFeatureClassDescriptor
    Set pFCDescriptor = New FeatureClassDescriptor
    pFCDescriptor.Create pFClass, Nothing, sFieldName
    
    'Create the Semi-variogram
    Dim pSemiVariogram As IGeoAnalysisSemiVariogram
    Set pSemiVariogram = New GeoAnalysisSemiVariogram
    
    'Define and set the parameters
    Dim dRange As Double
    Dim dSill As Double
    Dim dNugget As Double
    Dim dLag As Double
    dRange = 2.6185
    dSill = 542.65
    dNugget = 0
    dLag = 0.4496
    pSemiVariogram.Lag = dLag
    pSemiVariogram.DefineVariogram esriGeoAnalysisExponentialSemiVariogram, dRange, dSill, dNugget
    
    'Create radius using variable distance
    Dim pRadius As IRasterRadius
    Set pRadius = New RasterRadius
    pRadius.SetVariable 5
    
    'Create a RasterInterpolationOp object
    Dim pInterpolationOp As IInterpolationOp
    Set pInterpolationOp = New RasterInterpolationOp
    
    'Create Raster Analysis Environment
    Dim pEnv As IRasterAnalysisEnvironment
    Set pEnv = pInterpolationOp
    'set output cell size
    pEnv.SetCellSize esriRasterEnvValue, 1
    
    'Perform kriging interpolation using the semi-variogram method
    Dim pOutRaster As IRaster
    Set pOutRaster = pInterpolationOp.Variogram(pFCDescriptor, pSemiVariogram, pRadius, False)
    
    'Add output into ArcMap as a raster layer
    Dim pOutRasLayer As IRasterLayer
    Set pOutRasLayer = New RasterLayer
    pOutRasLayer.CreateFromRaster pOutRaster
    pMap.AddLayer pOutRasLayer
End Sub