How to interpolate using RasterInterpolationOp and FeatureClassDescriptor


This sample code demonstrates how to interpolate a point shapefile/feature class to a raster by specifying a value field using a FeatureClassDescriptor 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 (sFieldName) and specify a cellsize (dCellSize) to fit your data.
  6. Set a reference to the ESRI GeoAnalyst Object Library.
  7. Run the sub from the Macros dialog.
[VBA]
Sub Interpolation_IDW()
    '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 a RasterInterpolationOp object
    Dim pInterpolationOp As IInterpolationOp
    Set pInterpolationOp = New RasterInterpolationOp
    
    'Set cellsize for output raster in the environment
    Dim dCellSize As Double
    dCellSize = 60
    
    Dim pEnv As IRasterAnalysisEnvironment
    Set pEnv = pInterpolationOp
    pEnv.SetCellSize esriRasterEnvValue, dCellSize
    
    'Create raster radius and specify variable distance
    Dim pRadius As IRasterRadius
    Set pRadius = New RasterRadius
    pRadius.SetVariable 12
    
    'Perform the interpolation
    Dim pOutRaster As IRaster
    Set pOutRaster = pInterpolationOp.IDW(pFCDescriptor, 2, pRadius)
    
    'Add output into ArcMap as a raster layer
    Dim pOutRasLayer As IRasterLayer
    Set pOutRasLayer = New RasterLayer
    pOutRasLayer.CreateFromRaster pOutRaster
    pMap.AddLayer pOutRasLayer
End Sub