Geocoding and Reverse Geocoding with the Locator

The Locator task allows you to perform geocoding and reverse geocoding operations. With the Locator, you can either find the geographic location of an address or the address of a geographic location. In the ArcGIS Runtime SDK for WPF the Locator allows you to perform geocoding and reverse geocoding operations on local or online services

Geocoding

Geocoding is the process of transforming a description of a location - such as an address or place name - to a geographical location on map. Reverse geocoding is the opposite process of finding the nearest address to a geographical location on a map. Addresses are fundamental for both geocoding and reverse geocoding and have some specific characteristic. An address contains certain address elements. An address element is an individual component of the address, such as house number, street name, street types, and postal codes. Address elements help in the geocoding search, pinpointing an address to a particular location. Addresses come in various different styles and formats, including street address, a place name, or a location that is identified by a code. A common address format used in the United States consists of the following series of address elements: house number, prefix direction, prefix type, street name; street type, suffix direction; and zone information such as city, state , and ZIP Code. Globally, addresses are represented in a range of different formats. However, while all these addresses differ to some degree, some things remain consistent. Each address consists of one more several address elements, presented in a particular address format recognized by those in the region.

The locator is the major component in the geocoding process and contains all the data necessary to perform address matching. A locator is created based on a specific address locator style. Once created, an address locator contains the geocoding properties and parameters that are set, a snapshot of the address attributes in the reference data, and the queries for performing a geocoding search. The address locator also contains a set of address parsing and matching rules that directs the geocoding engine to perform address standardization and matching.

To perform geocoding and reverse geocoding successfully you will need to access an existing locator hosted by Esri or create and configure your own. You can access a variety of online geocoding tasks published and hosted by Esri including address locators for Europe and North America, a street locator for the United States, and a world places locator. You can connect directly to these online tasks through ArcGIS Runtime SDK for WPF. These allow you to begin geocoding with online data right away without the need to create and configure an address locator yourself . Locators can be created and configured for use with local data using ArcGIS for Desktop as the authoring environment.

Creating a Locator

Reference data

To successfully create a locator you will need to build reference data. Reference data refers to a feature class containing the address attributes you want to search. Reference data that contains suitable address attributes for geocoding can be obtained from government agencies, such as U.S. Bureau of Census which distributes U.S. nationwide TIGER/Line files, state, county, or city offices; or commercial data vendors or providers. The reference data you choose will be determined to an large degree by the type of locator you want to create, also known as the locator style.

Locator style

The locator style specifies the type of addresses that can be geocoded, the field mapping for the reference data, and what output information of a match would be returned. It also contains information of how an address is parsed, searching methods for possible matches, and default values for the geocoding options.

There are a number of different address locator styles. Choosing the right one depends on knowing what type of reference data you have and in what format your addresses will be. For example, you can use the US Address - Dual Ranges address locator style for street centerline data containing left and right address ranges, directionals, street names, street types, and left and right ZIP Codes. Alternatively, if you want to geocode U.S. ZIP Code data, you can use the US Address 5-Digit ZIP address locator style for creating a ZIP Code address locator based on a ZIP Code point reference feature class.

Build the Locator using ArcGIS for Desktop

To build a Locator you can use ArcCatalog or the Create Address Locator (Geocoding) geoprocessing tool to create an address locator. For step-by-step instructions, refer to the topic Creating an address locator in the ArcGIS for Desktop Help.

User Interface

The Locator itself does not specify the user interface, therefore implementation is required to allow users to define the input and display the geometries and/or attributes of the results in your WPF Application. The best practice is to separate an application's presentation layer from its business logic. In WPF, XAML is intended to house the presentation layer, while the code-behind is for an application's business logic. There are numerous ways you might choose to expose the functionality to the user.

For reverse geocoding it might be by defining the geographic coordinates via a map click or selecting geographic coordinates from a textbox or listbox. Results for this operation could be displayed by adding graphics to the map in a graphics layer with map tips enabled, which include the textual location. The results could also just simply populate a Listbox or DataGrid.

Using the Locator Task with local data

You can use existing online Locator services directly with the Locator task class in the ESRI.ArcGIS.Client.Tasks namespace to perform geocoding and reverse geocoding. To use a Locator with the runtime local server to perform geocoding and reverse geocoding operations in your WPF application you will need to consume the locator via the LocalGeocodeService class in the ESRI.ArcGIS.Client.Local assembly. One approach to starting a local geocode service is shown in the following steps (example in C#):

Create a new ESRI.ArcGIS.Client.Local.LocalGeocodeService with the locator path and the locator name as input parameters.

LocalGeocodeService.GetServiceAsync("Locator Path", "Locator name", gs =>
{
});

Declare and instantiate the ESRI.ArcGIS.Client.Tasks.Locator class. Set the local geocode service that the task will use to lookup addresses by passing the LocalGeocodeService's URL to the task's constructor.

LocalGeocodeService.GetServiceAsync("Locator Path", "Locator name", gs =>
{
Locator locatorTask = new Locator(gs.UrlGeocodeService);
});

Using the Locator Task with online data

To use the Locator with online data you will be required to pass the URL of an online service or layer. To find the URL, you can use the ArcGIS Services Directory. An example is below:

Locator locatorTask = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/"
 + "ESRI_Geocode_USA/GeocodeServer");

Input Parameters

Before using the Geocoding operations you will need to define the operation's input parameters. These parameters will vary depending on the operation. The key parameter is the address parameter, which is a dictionary that contains key/value pairs representing the various address fields accepted by the corresponding geocode service. These fields are listed in the addressFields property of the associated geocode service resource.

The Outfield parameter is the list of fields to include in the result set returned by the operation. If you specify the shape field in the list of return fields, it is ignored. For non-intersection addresses you can specify the candidate fields as defined in the geocode service. For intersection addresses you can specify the intersection candidate fields. The OutSpatialReference parameter allows the user to get or set the output spatial reference for the returning coordinates. Execute the locator task with the parameters specified by the AddressParameters member variable.

Results

To access the results for a geocoding operation a handler will need to be declared for the Address Locator task's AddressToLocationsCompleted event. This handler will be invoked when a geocoding operation is complete. A list of AddressCandidates containing information about the possible matches for the input address is passed to the handler's args parameter. Each AddressCandidate contains the score, address, and location for the match.

If results were found, loop through them and store a reference to the one with the highest match score. There are various output interfaces available to display the results in your WPF application. To display the results on the map you can create a graphic and display the graphic on the map by adding it to a graphics layer. To add the address of the result to the graphic you can use MapTips and specify and attribute name of Address, which will allow the value to be bound to the MapTip.

For reverse geocoding results, declare a handler for the Address Locator task's LocationToAddressCompleted event. This handler will be invoked when a reverse geocoding operation is complete. The address information for the address closest to the input point is passed to the handler's args parameter. There are various ways to display the results. One way is to get references to the found address and its attributes and create a Graphic with MapTips to display the address.

1/27/2015