Rematching a Geocoded Feature Class Automatically


This VBA code demonstrates how to rematch a geocoded feature class automatically.

To rematch a geocoded feature class, you must get the Locator that was attached to the feature class when it was created. You can then use the Locator to rematch the feature class.

This sample presents the Geododing Properties dialog to the user to specify the geocoding properties to use when rematching the feature class. These settings can also be specified programmatically on the Locator.

When rematching a feature class, you can specify a "where clause" that the Locator uses to determine which features to rematch. This clause is formatted as a SQL where clause. You use the Query dialog to construct this where clause.

How to use:
  1. Paste this code into VBA in ArcCatalog.
  2. In the ArcCatalog tree, select a geocoded feature class or shapefile.
  3. When prompted, set the geocoding options to use to rematch the geocoded feature class.
Option Explicit

Private Const MESSAGEBOX_TITLE = "Rematch Automatically Geocoding Developer Tip"

Public Sub RematchAutomatically()

  Dim pAddressUI As esriCore.IAddressUI    'address UI for the Locator
  Dim pAdvancedGeocoding As esriCore.IAdvancedGeocoding   'IAdvancedGeocoding interface on the Locator
  Dim pAttachedLocator As esriCore.IAttachedLocator   'AttachedLocator for the selected Dataset
  Dim pGxApplication As esriCore.IGxApplication   'ArcCatalog application
  Dim pGxDataset As esriCore.IGxDataset   'selected Dataset
  Dim pGxObject As esriCore.IGxObject   'selected object
  Dim pLocator As esriCore.ILocator   'Locator used to geocode the selected Dataset
  Dim pLocatorManager As esriCore.ILocatorManager   'LocatorManager object
  '** get a reference to the parent application
  If Not (TypeOf ThisDocument.Parent Is esriCore.IGxApplication) Then
    MsgBox "This macro can only be used in ArcCatalog.", vbCritical, MESSAGEBOX_TITLE
    Exit Sub
  End If
  Set pGxApplication = ThisDocument.Parent
  '** get a reference to the seleted geocoded feature class
  Set pGxObject = pGxApplication.SelectedObject
  If Not TypeOf pGxObject Is esriCore.IGxDataset Then
    MsgBox "The selected item is not a geocoded feature class.", vbCritical, _
    Exit Sub
  End If
  Set pGxDataset = pGxObject
  '** determine if the selected dataset is a geocoded feature class
  Set pLocatorManager = New esriCore.LocatorManager
  If Not pLocatorManager.HasLocatorAttached(pGxDataset.DatasetName) Then
    MsgBox "The selected item is not a geocoded feature class.", vbCritical, _
    Exit Sub
  End If
  '** get the attached locator from the dataset
  Set pAttachedLocator = pLocatorManager.GetLocatorFromDataset(pGxDataset.Dataset)
  Set pLocator = pAttachedLocator.Locator
  '** allow the user to change the runtime options for the Locator
  Set pAddressUI = pLocator.UserInterface
  pAddressUI.RuntimeOptions ThisDocument.Parent.hWnd, pLocator, False

  '** rematch the geocoded feature class
  Set pAdvancedGeocoding = pLocator
  With pAttachedLocator
    pAdvancedGeocoding.RematchTable .InputTable, .InputFieldNamesList, .InputJoinFieldName, _
      .OutputTable, .OutputFieldNamesList, .OutputJoinFieldName, ""
  End With

End Sub