This VBA sample demonstrates the IDW interpolator using a field from a related table in a FeatureClassDescriptor.
How to use
- Start ArcMap
- Add a point shapefile and a related table to ArcMap
- Define a join between the shapefile and the table
- Paste the following code into a VB Editor module
- Change the related field name (sRelField) and cell size (dCellSize) to match your data
- Set a reference to the ESRI GeoAnalyst Object Library
- Run IDW_From_Related_Table from the Macros dialog
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