Using FeatureClassDescriptor in an interpolation operation


FeatureClassDescriptor provides a way of using values of a specified field or fields. This code shows an example of performing interpolation on a value field in a shape file using FeatureClassDescriptor.

How to use:
  1. Start ArcMap.
  2. Add a shapefile that has a value field into ArcMap.
  3. Make sure that the Spatial Analyst Extension is turned on. Click Tools, click Extensions, and then check the Spatial Analyst extension.
  4. Paste the following code into VBA.
  5. Change the field name and cell size in the code to fit your data.
  6. Set a reference to the ESRI Spatial Analyst Shared Object Library. In the Visual Basic Editor, click Tools and then click References to display the References dialog box. Check "ESRI Spatial Analyst Shared Object Library" in the Available References list.
  7. Run the procedure: UsingFeatureClassDescriptor().
Sub UsingFeatureClassDescriptor()
     ' Set the two variables to fit your data
     Dim sFieldName As String
    Dim CellSize As Double
    sFieldName = "height"  'Field name used in interpolation
    CellSize = 60  'Cell size for output raster

     ' Get Map
     Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap

     ' Get feature class from layer
     Dim pFLayer As IFeatureLayer
    Set pFLayer = pMap.Layer(0)
    Dim pFClass As IFeatureClass
    Set pFClass = pFLayer.FeatureClass

     ' Create FeatureClassDescriptor using a value field
     Dim pFDescr As IFeatureClassDescriptor
    Set pFDescr = New FeatureClassDescriptor
    pFDescr.Create pFClass, Nothing, sFieldName
     ' 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, CellSize

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

     ' Using FeatureClassDescriptor as an input to the IInterpolationOp and
    ' Perform the interpolation
     Dim pOutRaster As IRaster
    Set pOutRaster = pIntOp.IDW(pFDescr, 2, pRadius)

     ' Add the result to layer
     Dim pRLayer As IRasterLayer
    Set pRLayer = New RasterLayer
    pRLayer.CreateFromRaster pOutRaster
    pMap.AddLayer pRLayer
End Sub