How to interpolate using a related field in FeatureClassDescriptor


This VBA sample demonstrates the IDW interpolator using a field from a related table in a FeatureClassDescriptor.

How to use

  1. Start ArcMap
  2. Add a point shapefile and a related table to ArcMap
  3. Define a join between the shapefile and the table
  4. Paste the following code into a VB Editor module
  5. Change the related field name (sRelField) and cell size (dCellSize) to match your data
  6. Set a reference to the ESRI GeoAnalyst Object Library
  7. Run IDW_From_Related_Table from the Macros dialog
[VBA]
Sub IDW_From_Related_Table()
    
    Dim sRelField As String
    Dim dCellSize As Double
    
    'Change the following to run this sample
    sRelField = "related.PROP"
    dCellSize = 2
    
    'Get the first layer from the current focus map
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pLayer As ILayer
    Set pLayer = pDoc.FocusMap.Layer(0)
    
    'Make a feature layer
    Dim pFLayer As IFeatureLayer
    Set pFLayer = pLayer
    
    'Get the display table
    Dim pDisplayTable As IDisplayTable
    Set pDisplayTable = pFLayer
    Dim pTable As ITable
    Set pTable = pDisplayTable.DisplayTable
    
    'Make a relationship query table from the display table
    Dim pRelQueryTable As IRelQueryTable
    Set pRelQueryTable = pTable
    
    'Get the feature class from the relationship query table
    Dim pFeatClass As IFeatureClass
    Set pFeatClass = pRelQueryTable
    
    'Make a feature class descriptor from the feature class
    Dim pFDesc As IFeatureClassDescriptor
    Set pFDesc = New FeatureClassDescriptor
    pFDesc.Create pFeatClass, Nothing, sRelField
    
    'Make a new interpolator object
    Dim pInterpolationOp As IInterpolationOp
    Set pInterpolationOp = New RasterInterpolationOp
    
    'Set the analysis environment
    Dim pRasterAnalysisEnv As IRasterAnalysisEnvironment
    Set pRasterAnalysisEnv = pInterpolationOp
    pRasterAnalysisEnv.SetCellSize esriRasterEnvValue, CVar(dCellSize)
    pRasterAnalysisEnv.SetExtent esriRasterEnvMaxOf
    
    'Set the search radius
    Dim pRasterRadius As IRasterRadius
    Set pRasterRadius = New RasterRadius
    pRasterRadius.SetFixed 50, 10
    
    'Perform the IDW
    Dim pRaster As IRaster
    Set pRaster = New Raster
    Set pRaster = pInterpolationOp.IDW(pFDesc, 2, pRasterRadius)
    
    'Create a new raster layer
    Dim pRasterLayer As IRasterLayer
    Set pRasterLayer = New RasterLayer
    pRasterLayer.CreateFromRaster pRaster
    
    'Add the layer to the current focus map
    pDoc.FocusMap.AddLayer pRasterLayer
    pDoc.UpdateContents
    pDoc.ActiveView.Refresh
End Sub