How to geocode a table of addresses


Summary
If you have a table of addresses to locate (for example, in ArcSDE), you can locate all of them by using the MatchTable method.

Geocoding a table of addresses

Use the MatchTable method to geocode a table of addresses. The AddressTable parameter is a reference to the table object that contains the addresses to geocode. The addressFieldNames parameter is a comma-delimited string containing the names of the fields in the address table that contain the address information. The names of the fields in this string must be specified in the same order as the Field objects in the Field collections returned by the AddressFields property on the IAddressInputs interface.
When geocoding a table of addresses, you must create the feature class that contains the geocoded features and pass it to the MatchTable method using the outputFeatureClass parameter. At a minimum, the geocoded feature class must contain an ObjectID field and the match fields defined by the MatchFields property, as well as a copy of all the fields from the address table that contains the address information.
The outputFieldNames parameter is a comma-delimited string that contains the names of the match fields in the geocoded feature class. The names of the fields in this string must be specified in the same order as the Field objects in the Field collections returned by the MatchFields property. The fieldsToCopy parameter is a PropertySet defining the fields from the address table to copy to the output feature class. The names of the properties are the names of the fields in the output feature class, and the names of the properties are the names of the corresponding fields in the address table.
Once you have used the MatchTable method to geocode a table of addresses, use the AttachLocator method on the ILocatorAttach2 on the LocatorWorkspace to attach a copy of the locator to the geocoded feature class. See the following code example:
[Java]
// Open an ArcSDE workspace.
IPropertySet connProperties = new PropertySet();
connProperties.setProperty("server", "mendota");
connProperties.setProperty("instance", "esri_sde");
connProperties.setProperty("database", "arcobjects");
connProperties.setProperty("user", "sde");
connProperties.setProperty("password", "sde");
connProperties.setProperty("version", "SDE.Default");
IWorkspaceFactory factory = new SdeWorkspaceFactory();
IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(factory.open
    (connProperties, 0));

// Get a locator from the DatabaseLocatorWorkspace.
ILocatorManager locatorManager = new LocatorManager();
ILocatorWorkspace locatorWorkspace = locatorManager.getLocatorWorkspace(new
    IWorkspaceProxy(featureWorkspace));
IAddressGeocoding addressGeocoding = new IAddressGeocodingProxy
    (locatorWorkspace.getLocator("SDE.Redlands_ZIP"));

// Open the table to geocode.
ITable addressTable = featureWorkspace.openTable("arcobjects.sde.REDLANDS_ADDRESS");

// Create a feature class to contain the geocoding results.
// The feature class must contain an ObjectID field, all of the match fields returned by the locator,
// and fields that contain the address input values.
IFieldsEdit fieldsEdit = new Fields();
IFieldEdit fieldEdit = new Field();

// Add an ObjectID field.
fieldEdit.setName("OBJECTID");
fieldEdit.setType(esriFieldType.esriFieldTypeOID);
fieldsEdit.addField(fieldEdit);

// Add the match fields.
IFields matchFields = addressGeocoding.getMatchFields();
for (int i = 0; i < matchFields.getFieldCount(); i++)
    fieldsEdit.addField(matchFields.getField(i));


// Add the address fields.
IFields addressFields = addressTable.getFields();
IPropertySet fieldsToCopy = new PropertySet();
fieldEdit = (IFieldEdit)addressFields.getField(addressFields.findField("ADDRESS"));
fieldEdit.setName("ARC_ADDRESS");
fieldsEdit.addField(fieldEdit);
fieldsToCopy.setProperty("ARC_ADDRESS", "ADDRESS");
fieldEdit = (IFieldEdit)addressFields.getField(addressFields.findField("ZIP"));
fieldEdit.setName("ARC_ZIP");
fieldsEdit.addField(fieldEdit);
fieldsToCopy.setProperty("ARC_ZIP", "ZIP");
UID uid = new UID();
uid.setValue("esriGeodatabase.Feature");
IFeatureClass featureClass = featureWorkspace.createFeatureClass("REDLANDS_LOCATION",
    fieldsEdit, uid, null, esriFeatureType.esriFTSimple, "Shape", "");

// Geocode the table into the feature class.
addressGeocoding.matchTable(addressTable, "ADDRESS,ZIP", "", featureClass, 
    "Shape,Status,Score,Side", fieldsToCopy, null);

// Attach the locator to the geocoded feature class.
ILocatorAttach2 locatorAttach = new ILocatorAttach2Proxy(locatorWorkspace);
locatorAttach.attachLocator(new ILocatorProxy(addressGeocoding), new ITableProxy
    (featureClass), "ARC_ADDRESS,ARC_ZIP", "Shape,Status,Score,Side");


See Also:

Location library overview
How to geocode a single address




Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced