How to rematch 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 Geocoding 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. Run the RematchAutomatically macro.
  4. When prompted, set the geocoding options to use to rematch the geocoded feature class.
[VBA]
Private Const MESSAGEBOX_TITLE = "Rematch Automatically Geocoding Developer Tip"

Public Sub RematchAutomatically()
    
    Dim pAddressUI As esriLocationUI.IAddressUI '+++ address UI for the locator
    Dim pAdvancedGeocoding As esriLocation.IAdvancedGeocoding '+++ IAdvancedGeocoding interface on the locator
    Dim pAttachedLocator As esriLocation.IAttachedLocator '+++ AttachedLocator for the selected dataset
    Dim pGxApplication As esriCatalogUI.IGxApplication '+++ reference to the parent ArcCatalog application
    Dim pGxDataset As esriCatalog.IGxDataset '+++ selected GXDataset
    Dim pGxObject As esriCatalog.IGxObject '+++ selected GXObject
    Dim pLocator As esriGeoDatabase.ILocator '+++ the locator used to geocode the selected dataset
    Dim pLocatorManager As esriLocation.ILocatorManager '+++ LocatorManager object
    
    '+++ get a reference to the parent application
    If Not (TypeOf ThisDocument.Parent Is esriCatalogUI.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 esriCatalog.IGxDataset Then
        MsgBox "The selected item is not a geocoded feature class.", vbCritical, MESSAGEBOX_TITLE
        Exit Sub
    End If
    Set pGxDataset = pGxObject
    '+++ determine if the selected dataset is a geocoded feature class
    Set pLocatorManager = New esriLocation.LocatorManager
    If Not pLocatorManager.HasLocatorAttached(pGxDataset.DatasetName) Then
        MsgBox "The selected item is not a geocoded feature class.", vbCritical, MESSAGEBOX_TITLE
        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






Additional Requirements
  • A geocoded shapefile or feature class.