How to find the address closest to a point using reverse geocoding
Development licensing
Deployment licensing
Engine Developer Kit
Engine Runtime
ArcView
ArcView
ArcEditor
ArcEditor
ArcInfo
ArcInfo
Finding the address closest to a point using reverse geocoding
When given a location on a map, if you want to find the address closest to that point, use reverse geocoding. The IReverseGeocoding and IReverseGeocodingProperties interfaces provide access to members for finding the address closest to a point.
To define the maximum search tolerance in the units specified by the SearchDistanceUnits property, use the SearchDistance property when looking for an address represented by a point.
The ReverseGeocode method returns a PropertySet that represents the address closest to the point passed as the location parameter.
The point object passed to the location parameter must be projected into the spatial reference used by the locator before it is passed to the ReverseGeocode parameter.
Use the bReturnIntersection parameter to indicate whether the ReverseGeocode method should return an intersection address. The names of the properties contained in the PropertySet correspond to the names of the Field objects in the Fields collection returned by the AddressFields property on the IAddressInputs interface on the locator. See the following:
[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 pReverseGeocoding As ESRI.ArcGIS.Location.IReverseGeocoding
Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
Dim pAddressGeocoding As ESRI.ArcGIS.Location.IAddressGeocoding
Dim pMatchFields As ESRI.ArcGIS.Geodatabase.IFields
Dim pShapeField As ESRI.ArcGIS.Geodatabase.IField
Dim pReverseGeocodingProperties As ESRI.ArcGIS.Location.IReverseGeocodingProperties
Dim pAddressProperties As ESRI.ArcGIS.esriSystem.IPropertySet
Dim pAddressInputs As ESRI.ArcGIS.Location.IAddressInputs
Dim pAddressFields As ESRI.ArcGIS.Geodatabase.IFields
Dim lngAddressFieldIndex AsLongDim pAddressField As ESRI.ArcGIS.Geodatabase.IField
' Open an ArcGIS Server connection.
pConnectionProperties = New ESRI.ArcGIS.esriSystem.PropertySetClass
pConnectionProperties.SetProperty("machine", "mendota")
pAGSServerConnectionFactory = New ESRI.ArcGIS.GISClient.AGSServerConnectionFactoryClass
pAGSServerConnection = pAGSServerConnectionFactory.Open(pConnectionProperties, 0)
' Get a locator from the ArcGIS Server locator workspace.
pLocatorManager = New ESRI.ArcGIS.Location.LocatorManagerClass
pLocatorWorkspace = pLocatorManager.GetAGSLocatorWorkspace(pAGSServerConnection.FullName)
pReverseGeocoding = pLocatorWorkspace.GetLocator("USA Streets")
' Create a point to find the address.
pAddressGeocoding = pReverseGeocoding
pMatchFields = pAddressGeocoding.MatchFields
pShapeField = pMatchFields.Field(pMatchFields.FindField("Shape"))
pPoint = New ESRI.ArcGIS.Geometry.PointClass
pPoint.SpatialReference = pShapeField.GeometryDef.SpatialReference
pPoint.X = -117.2
pPoint.Y = 34.06
' Set the search tolerance for reverse geocoding.
pReverseGeocodingProperties = pReverseGeocoding
pReverseGeocodingProperties.SearchDistance = 100
pReverseGeocodingProperties.SearchDistanceUnits = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters
' Find the address nearest the point.
pAddressProperties = pReverseGeocoding.ReverseGeocode(pPoint, False)
' Print the address properties.
pAddressInputs = pReverseGeocoding
pAddressFields = pAddressInputs.AddressFields
For lngAddressFieldIndex = 0 To pAddressFields.FieldCount - 1
pAddressField = pAddressFields.Field(lngAddressFieldIndex)
Debug.Print(pAddressField.AliasName & ": " & pAddressProperties.GetProperty(pAddressField.Name))
Next lngAddressFieldIndex