How to create address locators


Summary
When geocoding, you must create an address locator before you can locate an address.

In this topic


Creating address locators

There are a few ways to create an address locator. In most cases, it is recommended that you use the geoprocessing tool. However, you can also create one using the underlying ArcObjects.

Using the geoprocessing tool

Usually, the recommended way to create an address locator is to use the CreateAddressLocator geoprocessing tool located in the Geocoding toolbox. See the following code example:
[Java]
String dataGDB = "C:\\data\Atlanta.gdb";
String featureclass = "streets";
//Put quotes around the path name so that it works with spaces.
String referenceData = "\"" + dataGDB + "\\" + featureclass + "\" 'Primary table'";
String locatorName = "Street Locator";
String addressLocatorStyle = "US Address - Dual Ranges";

// The field mapping syntax is "'What geocoding needs' NAME_OF_FIELD_IN_DATASET;"
String fieldMapping = "'*From Left' L_F_ADD;" + "'*To Left' L_T_ADD;" + 
    "'*From Right' R_F_ADD;" + "'*To Right' R_T_ADD;" + "'Prefix Direction' PREFIX;"
    + "'Prefix Type' PRE_TYPE;" + "'*Street Name' NAME;" + "'Street Type' TYPE;" + 
    "'Suffix Direction' SUFFIX" + "'Left City or Place' CITYL" + 
    "'Right City or Place' CITYR" + "'Left ZIP Code' ZIPL" + "'Right ZIP Code' ZIPR"
    + "'Left State' STATE_ABBR" + "'Right State' STATE_ABBR";

GeoProcessor gp = new GeoProcessor();
CreateAddressLocator addressLocatorGPTool = new CreateAddressLocator
    (addressLocatorStyle, referenceData, fieldMapping, dataGDB + "\\" + locatorName);
gp.execute(addressLocatorGPTool, null);

Using the underlying ArcObjects

The following code example shows how to use the locator workspace, address locator style, and address locator reference data objects to create an ESRIGen2AddressLocator:
[Java]
// Open the default local locator workspace to get the locator style.
ILocatorManager2 locatorManager = new LocatorManager();
ILocatorWorkspace locatorWorkspace = locatorManager.getLocatorWorkspaceFromPath("");

// Get the locator style to base the new locator.
ILocatorStyle locatorStyle = locatorWorkspace.getLocatorStyle(
    "US Address - Dual Ranges");

// Open the feature class to use as reference data.
IWorkspaceFactory2 factory = new AccessWorkspaceFactory();
IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(factory.openFromFile
    ("D:\\workspace\\arcobjects\\location\\redlands.mdb", 0));
IDataset pDataset = new IDatasetProxy(featureWorkspace.openFeatureClass("Streets"));

// Set the feature class as the primary reference data table for the locator.
IReferenceDataTables dataTables = (IReferenceDataTables)locatorStyle;
IEnumReferenceDataTable enumDataTables = dataTables.getTables();
enumDataTables.reset();
IReferenceDataTableEdit dataTableEdit = (IReferenceDataTableEdit)enumDataTables.next
    ();
dataTableEdit.setNameByRef(new ITableNameProxy(pDataset.getFullName()));

// Store the new locator in the same workspace as the reference data.
if (dataTables.isHasEnoughInfo()){
    locatorWorkspace = locatorManager.getLocatorWorkspaceFromPath(
        "D:\\workspace\\arcobjects\\location\\redlands.mdb");
    ILocator locator = locatorWorkspace.addLocator("New Redlands Locator", new
        ILocatorProxy(locatorStyle), "", null);
}
The following code example shows how to use the locator workspace and address locator style objects to create an ArcSDE locator:
[Java]
// Open an ArcSDE workspace.
IPropertySet connectionProps = new PropertySet();
connectionProps.setProperty("server", "mendota");
connectionProps.setProperty("instance", "esri_sde");
connectionProps.setProperty("database", "arcobjects");
connectionProps.setProperty("user", "sde");
connectionProps.setProperty("password", "sde");
connectionProps.setProperty("version", "SDE.Default");

IWorkspaceFactory factory = new SdeWorkspaceFactory();
IWorkspace workspace = factory.open(connectionProps, 0);

//Open the database locator workspace for the ArcSDE workspace.
ILocatorManager locatorManager = new LocatorManager();
ILocatorWorkspace locatorWorkspace = locatorManager.getLocatorWorkspace(workspace);


// Get the U.S. streets locator style.
ILocatorStyle locatorStyle = locatorWorkspace.getLocatorStyle(
    "US Address - Dual Ranges");

// Open the feature workspace containing the reference data.
// Set the reference data on the new locator.
IDataset dataset = new IDatasetProxy(new IFeatureWorkspaceProxy(workspace)
    .openFeatureClass("sde.SDE.altanta_st"));
IReferenceDataTables dataTables = (IReferenceDataTables)locatorStyle;
IEnumReferenceDataTable enumDataTables = dataTables.getTables();
enumDataTables.reset();
IReferenceDataTableEdit dataTableEdit = (IReferenceDataTableEdit)enumDataTables.next
    ();
dataTableEdit.setNameByRef(new ITableNameProxy(dataset.getFullName()));

// Store the locator if the reference data is properly specified.
if (dataTables.isHasEnoughInfo()){
    ILocator locator = locatorWorkspace.addLocator("My New SDE Locator", new
        ILocatorProxy(locatorStyle), "", null);
}






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