| Development licensing |
Deployment licensing |
| Engine Developer Kit |
Engine Runtime |
| ArcView |
ArcView |
| ArcEditor |
ArcEditor |
| ArcInfo |
ArcInfo |
Geocoding a single address
There are a two ways to geocode a single address:
Using IAddressGeocoding and MatchAddress
The following is the primary way to geocode a single address:
- Once you have the locator, set the address parameters, then call MatchAddress. The address parameter is a PropertySet containing properties that represent the input address components used by the locator. Use the AddressFields property on the IAddressInputs interface to determine the input address components used by the locator.
- The MatchFields property of the address locator contains the coordinates of the points that match the address that was passed in. The MatchFields property returns a Field collections where the names of the Field objects correspond to the names of the properties in the PropertySet returned by the MatchAddress method.
See the following code example:
[VB.NET]
Dim pConnectionProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pAGSServerConnectionFactory As ESRI.ArcGIS.GISClient.IAGSServerConnectionFactory
Dim pAGSServerConnection As ESRI.ArcGIS.GISClient.IAGSServerConnection
Dim pLocatorManager As ESRI.ArcGIS.Location.ILocatorManager2
Dim pLocatorWorkspace As ESRI.ArcGIS.Geodatabase.ILocatorWorkspace
Dim pAddressGeocoding As ESRI.ArcGIS.Location.IAddressGeocoding
Dim pAddressProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pMatchProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pMatchFields As ESRI.ArcGIS.Geodatabase.IFields
Dim lngMatchFieldIndex As Long
Dim pMatchField As ESRI.ArcGIS.Geodatabase.IField
Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
' Open an AGSServerConnection.
pConnectionProperties = New ESRI.ArcGIS.esriSystem.PropertySetClass
pConnectionProperties.SetProperty("machine", "mendota")
pAGSServerConnectionFactory = New ESRI.ArcGIS.GISClient.AGSServerConnectionFactoryClass
pAGSServerConnection = pAGSServerConnectionFactory.Open(pConnectionProperties, 0)
' Open the AGSLocatorWorkspace.
pLocatorManager = New ESRI.ArcGIS.Location.LocatorManagerClass
pLocatorWorkspace = pLocatorManager.GetAGSLocatorWorkspace(pAGSServerConnection.FullName)
' Get a locator from the AGSLocatorWorkspace.
pAddressGeocoding = pLocatorWorkspace.GetLocator("USA Streets")
' Geocode an address using the locator.
pAddressProperties = New ESRI.ArcGIS.esriSystem.PropertySetClass
With pAddressProperties
.SetProperty("Street", "380 New York St.")
.SetProperty("City", "Redlands")
.SetProperty("State", "CA")
.SetProperty("ZIP", "92373")
End With
pMatchProperties = pAddressGeocoding.MatchAddress(pAddressProperties)
' Print the match properties.
pMatchFields = pAddressGeocoding.MatchFields
For lngMatchFieldIndex = 0 To pMatchFields.FieldCount - 1
pMatchField = pMatchFields.Field(lngMatchFieldIndex)
If pMatchField.Type = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry Then
pPoint = pMatchProperties.GetProperty(pMatchField.Name)
If Not pPoint.IsEmpty Then
Debug.Print("X: " & pPoint.X)
Debug.Print("Y: " & pPoint.Y)
End If
Else
Debug.Print(pMatchField.AliasName & ": " & pMatchProperties.GetProperty(pMatchField.Name))
End If
Next lngMatchFieldIndex
A GeocodeServer is a ServerObject delivered by an ArcGIS Server that can be used to geocode addresses. Internally, a GeocodeServer uses an address locator to do the geocoding and exposes the high-level functionality of the address locator using the IGeocodeServer interface.
Generally, GeocodeServer objects will be used by ArcGIS Server developers to create server applications that include geocoding functionality. However, ArcGIS Desktop and ArcGIS Engine developers can use GeocodeServer objects to include geocoding functionality in ArcGIS Desktop customizations and custom applications using only the high-level geocoding functionality exposed by a GeocodeServer.
See the following code example:
[VB.NET]
Dim pGISServerConnection As ESRI.ArcGIS.Server.IGISServerConnection
Dim pServerObjectManager As ESRI.ArcGIS.Server.IServerObjectManager
Dim pServerContext As ESRI.ArcGIS.Server.IServerContext
Dim pGeocodeServer As ESRI.ArcGIS.Location.IGeocodeServer
Dim pAddressProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pLocatorProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pMatchProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pMatchFields As ESRI.ArcGIS.Geodatabase.IFields
Dim lngMatchFieldIndex As Long
Dim pMatchField As ESRI.ArcGIS.Geodatabase.IField
Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
' Open a GISServerConnection.
pGISServerConnection = New ESRI.ArcGIS.Server.GISServerConnectionClass
pGISServerConnection.Connect("mendota")
' Get a GeocodeServer from the GISServerConnection.
pServerObjectManager = pGISServerConnection.ServerObjectManager
pServerContext = pServerObjectManager.CreateServerContext("USA Streets", "GeocodeServer")
pGeocodeServer = pServerContext.ServerObject
' Construct an address PropertySet to geocode.
pAddressProperties = pServerContext.CreateObject("esriSystem.PropertySet")
With pAddressProperties
.SetProperty("Street", "380 New York St.")
.SetProperty("City", "Redlands")
.SetProperty("State", "CA")
.SetProperty("ZIP", "92373")
End With
' Set the geocoding properties to use to geocode the address.
pLocatorProperties = pGeocodeServer.GetLocatorProperties
pLocatorProperties.SetProperty("MinimumMatchScore", "100")
pLocatorProperties.SetProperty("SpellingSensitivity", "100")
' Geocode the address.
pMatchProperties = pGeocodeServer.GeocodeAddress(pAddressProperties, pLocatorProperties)
' Print the match properties.
pMatchFields = pGeocodeServer.GetResultFields(Nothing)
For lngMatchFieldIndex = 0 To pMatchFields.FieldCount - 1
pMatchField = pMatchFields.Field(lngMatchFieldIndex)
If pMatchField.Type = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry Then
pPoint = pMatchProperties.GetProperty(pMatchField.Name)
If Not pPoint.IsEmpty Then
Debug.Print("X: " & pPoint.X)
Debug.Print("Y: " & pPoint.Y)
End If
Else
Debug.Print(pMatchField.AliasName & ": " & pMatchProperties.GetProperty(pMatchField.Name))
End If
Next lngMatchFieldIndex
See Also:
How to geocode a table of addressesLocation library overview