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:
[Java]
// Open an ArcGIS Server connection.
IPropertySet pConnectionProperties = new PropertySet();
pConnectionProperties.setProperty("machine", "mendota");
IAGSServerConnectionFactory pAGSServerConnectionFactory = new
AGSServerConnectionFactory();
IAGSServerConnection pAGSServerConnection = pAGSServerConnectionFactory.open
(pConnectionProperties, 0);
// Get a locator from the ArcGIS Server locator workspace.
ILocatorManager2 pLocatorManager = new LocatorManager();
ILocatorWorkspace pLocatorWorkspace = pLocatorManager.getAGSLocatorWorkspace(new
IAGSServerConnectionNameProxy(pAGSServerConnection.getFullName()));
IReverseGeocoding pReverseGeocoding = new IReverseGeocodingProxy
(pLocatorWorkspace.getLocator("USA Streets"));
// Create a point to find the address.
IAddressGeocoding pAddressGeocoding = new IAddressGeocodingProxy(pReverseGeocoding);
IFields pMatchFields = pAddressGeocoding.getMatchFields();
IField pShapeField = pMatchFields.getField(pMatchFields.findField("Shape"));
IPoint pPoint = new Point();
pPoint.setSpatialReferenceByRef(pShapeField.getGeometryDef().getSpatialReference());
pPoint.setX( - 117.2);
pPoint.setY(34.06);
// Set the search tolerance for reverse geocoding.
IReverseGeocodingProperties pReverseGeocodingProperties = new
IReverseGeocodingPropertiesProxy(pReverseGeocoding);
pReverseGeocodingProperties.setSearchDistance(100);
pReverseGeocodingProperties.setSearchDistanceUnits(esriUnits.esriMeters);
// Find the address nearest the point.
IPropertySet pAddressProperties = pReverseGeocoding.reverseGeocode(pPoint, false);
// Print the address properties.
IAddressInputs pAddressInputs = new IAddressInputsProxy(pReverseGeocoding);
IFields pAddressFields = pAddressInputs.getAddressFields();
for (int lngAddressFieldIndex = 0; lngAddressFieldIndex <
pAddressFields.getFieldCount(); lngAddressFieldIndex++){
IField pAddressField = pAddressFields.getField(lngAddressFieldIndex);
System.out.println(pAddressField.getAliasName() + ": " +
pAddressProperties.getProperty(pAddressField.getName()));
}
See Also:
Location library overviewDevelopment licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine Runtime |
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |