This document is archived and information here might be outdated.  Recommended version.


How to rematch a geocoded feature class (ArcObjects .NET 10.5 SDK)

How to rematch a geocoded feature class


In this topic


Rematching a geocoded feature class

After geocoding a table of addresses, you can review the results. If you are not satisfied with the results, modify the address locator's settings, and geocode the table of addresses or records that were not matched again. This process is known as rematching.
The following are some of the ways to specify addresses in a geocode feature class that you want to rematch:
  • Only addresses that are unmatched
  • All addresses with a match score less than a certain value
  • All addresses with two or more candidates with the best match score
  • All addresses
  • Addresses based on a specified query

Using the geoprocessing tool

Run the RematchAddresses geoprocessing tool if the address table or locator has been updated, and the geocoded feature class needs to be updated to reflect the changes. See the following code example:
[VB.NET]
Public Sub RematchAddressesTool_Test()
    Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor=New ESRI.ArcGIS.Geoprocessor.Geoprocessor
    Dim rematchAddresses As RematchAddresses=New RematchAddresses()
    rematchAddresses.in_geocoded_feature_class="C:\UnitedStates.gdb\US_Locations"
    rematchAddresses.out_geocoded_feature_class="C:\UnitedStates.gdb\US_Locations"
    Try
    Dim result As IGeoProcessorResult=GP.Execute(rematchAddresses, Nothing)
    If (Not result Is Nothing) Then
        If (Not result.Status=esriJobStatus.esriJobSucceeded) Then
            Console.WriteLine("Failed to rematch the addresses: ")
        Else
            Console.WriteLine("Rematch addresses completed successfully. ")
        End If
    Else
        If (Not GP.MessageCount=0) Then
            For i As Integer=0 To GP.MessageCount - 1
                Console.WriteLine("GP Message " & i & " " + GP.GetMessage(i))
            Next
        Else
            Console.WriteLine("Execution failed with no status. ")
        End If
    End If
    Catch ex As Exception
    Console.WriteLine("An Exception occured while executing the RematchAddresses Tool:  " & ex.ToString())
    End Try
End Sub
[C#]
public void RematchAddressesTool()
{
    Geoprocessor GP=new Geoprocessor();
    RematchAddresses rematchAddresses=new RematchAddresses();
    rematchAddresses.in_geocoded_feature_class=
        "C:\\UnitedStates.gdb\\US_Locations";
    rematchAddresses.out_geocoded_feature_class=
        "C:\\UnitedStates.gdb\\US_Locations";
    try
    {
        IGeoProcessorResult result=GP.Execute(rematchAddresses, null)as
            IGeoProcessorResult;
        if (result != null)
        {
            if (result.Status != esriJobStatus.esriJobSucceeded)
                Console.WriteLine("Failed to rematch the addresses: ");
            else
                Console.WriteLine("Rematch addresses completed successfully. ");
        }
        else
        {
            if (GP.MessageCount != 0)
            {
                for (int i=0; i < GP.MessageCount; i++)
                {
                    Console.WriteLine("GP Message " + i + " " + GP.GetMessage(i));
                }
            }
            else
                Console.WriteLine("Execution failed with no status. ");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(
            "An Exception occured while executing the RematchAddresses Tool:  " + e);
    }
}

Using ArcObjects

The IBatchGeocoding interface has methods to match a record set or rematch a table.  Usually, you use the IBatchGeocoding interface to rematch a geocoded feature class using the RematchTable method.
The RematchTable method takes a number of parameters. Most of these parameters can be retrieved from the AttachedLocator object associated with the geocoded feature class.
Do the following steps to rematch a feature class:
  1. Open an ArcSDE workspace.
  2. Open the feature class to rematch.
  3. Get the locator that is attached to the feature class.
  4. Modify the geocoding properties on the locator and rematch the feature class.
See the following code example:
[VB.NET]
Public Sub RematchGeocodedFeatures()
    
    ' Open an ArcSDE workspace.
    Dim propertySet_Connection As IPropertySet=New PropertySetClass
    With propertySet_Connection
        .SetProperty("server", "mendota")
        .SetProperty("instance", "esri_sde")
        .SetProperty("database", "arcobjects")
        .SetProperty("user", "sde")
        .SetProperty("password", "sde")
        .SetProperty("version", "SDE.Default")
    End With
    
    Dim obj As System.Object=Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"))
    Dim workspaceFactory As IWorkspaceFactory=CType(obj, IWorkspaceFactory)
    Dim workspace As IWorkspace=workspaceFactory.Open(propertySet_Connection, 0)
    Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace=CType(workspace, IFeatureWorkspace)
    
    ' Open the feature class to rematch.
    Dim featureClass As IFeatureClass=featureWorkspace.OpenFeatureClass("arcobjects.SDE.REDLANDS_LOCATION")
    
    ' Get the locator that is attached to the feature class.
    obj=Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager=CType(obj, ILocatorManager)
    Dim dataset As IDataset=CType(featureClass, IDataset)
    Dim attachedLocator As IAttachedLocator=locatorManager.GetLocatorFromDataset(dataset)
    Dim locator As ILocator=attachedLocator.Locator
    Dim batchGeocoding As IBatchGeocoding=CType(locator, IBatchGeocoding)
    
    ' Modify the geocoding properties on the locator and rematch the feature class.
    Dim geocodingProperties As IGeocodingProperties=CType(batchGeocoding, IGeocodingProperties)
    geocodingProperties.MinimumMatchScore=100
    With attachedLocator
        Dim table As ITable=.OutputTable
        batchGeocoding.RematchTable(.InputTable, .InputFieldNamesList, .InputJoinFieldName, CType(table, IFeatureClass), .OutputFieldNamesList, .OutputJoinFieldName, "", Nothing)
    End With
    
End Sub
[C#]
public void RematchGeocodedFeatures()
{
    // Open an ArcSDE workspace.
    IPropertySet propertySet_Connection=new PropertySetClass();
    propertySet_Connection.SetProperty("server", "mendota");
    propertySet_Connection.SetProperty("instance", "esri_sde");
    propertySet_Connection.SetProperty("database", "arcobjects");
    propertySet_Connection.SetProperty("user", "sde");
    propertySet_Connection.SetProperty("password", "sde");
    propertySet_Connection.SetProperty("version", "SDE.Default");

    System.Object obj=Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory"));
    IWorkspaceFactory workspaceFactory=obj as IWorkspaceFactory;
    IWorkspace workspace=workspaceFactory.Open(propertySet_Connection, 0);
    IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)workspace;

    // Open the feature class to rematch.
    IFeatureClass featureClass=featureWorkspace.OpenFeatureClass(
        "arcobjects.SDE.REDLANDS_LOCATION");

    // Get the locator that is attached to the feature class.
    obj=Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager locatorManager=obj as ILocatorManager;
    IDataset dataset=(IDataset)featureClass;
    IAttachedLocator attachedLocator=locatorManager.GetLocatorFromDataset(dataset);
    ILocator locator=attachedLocator.Locator;
    IBatchGeocoding batchGeocoding=(IBatchGeocoding)locator;

    // Modify the geocoding properties on the locator and rematch the feature class.
    IGeocodingProperties geocodingProperties=(IGeocodingProperties)batchGeocoding;
    geocodingProperties.MinimumMatchScore=100;
    ITable table=attachedLocator.OutputTable;
    batchGeocoding.RematchTable(attachedLocator.InputTable,
        attachedLocator.InputFieldNamesList, attachedLocator.InputJoinFieldName, 
        (IFeatureClass)table, attachedLocator.OutputFieldNamesList,
        attachedLocator.OutputJoinFieldName, "", null);
}


See Also:

Location library overview




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):

Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced