Geocode service ReverseGeocode method

Returns the address closest to the given point, and within a specified search distance.

ReverseGeocode(Point Location, bool ReturnIntersection, PropertySet PropMods)

Parameter

Description

Location

A point (PointN) that represents the location at which to search for the closest address.

ReturnIntersection

A boolean value which indicates whether the geocode services should return the nearest intersection to the given point.

PropMods

A PropertySet containing the properties relevant for reverse geocoding. There are five valid properties: "ReverseDistance", "ReverseDistanceUnits", "SideOffset", "SideOffsetUnits", "OutputSpatialReference" (see Remarks for more information).

Use GetLocatorProperties() to return default locator properties.

Return Value

A PropertySet containing property-value pairs that describe the address. The names of the properties are the names of the fields returned by the GetAddressFields() method and their values correspond to the components of the nearest address. In addition, the geometry that represents the actual location of the closest address is returned in a shape field.

Remarks

The following diagram illustrates the geocode server proxy methods commonly used when working with the ReverseGeocode() method. In addition, the diagram also includes the input point and output address information one can expect when using this method.

Common geocode server ReverseGeocode() proxy methods

The input point passed to this method can have a different spatial reference than the reference data used by the geocode service. Set the PointN.SpatialReference property of the input point to a ProjectedCoordinateSystem or GeographicCoordinateSystem. Both coordinate system types can be defined using a well-known id (WKID) or text (WKT). If a spatial reference is not defined for an input point, the spatial reference of the geocode service is assumed. To get the spatial reference of a geocode service, use the GetResultFields() method to get the result fields then use the SpatialReference property on the shape field's GeometryDef object.

The following locator properties can be modified for each reverse geocode operation:

Property name

Type

Description

ReverseDistance

double

The distance from the input point to search for an address. The default value is 0.

ReverseDistanceUnits

string

The units in which to measure the "ReverseDistance" value. When specifying this property, use a string to indicate the units to use. For example, when searching for an address using a search distance specified in "esriMeters", use the string "Meters" to specify the search distance units. Refer to the esriUnits enumeration for a list of all supported search distance units.

The default value is "esriUnknownUnits".

SideOffset

integer

Geocode services can use reference data containing address range information for each side of the street, such as US Street address styles. Locators based on these styles can determine which side of the street an address is located.

In a reverse geocode operation, the side offset has a dual purpose. One, the point returned is a specified distance, the side offset, from the real segment on the correct side of the street. And two, the side offset is appended to the search tolerance (ReverseDistance) to find a location on a segment.

The following diagram illustrates how the side offset and reverse distance are used to define the actual search tolerance for a reverse geocode operation.

Side offset and reverse distance used in a reverse geocode operation

SideOffsetUnits

Unit

The reference unit in which to specify the side offset (SideOffset property).

OutputSpatialReference

SpatialReference

The output spatial reference for the reverse geocoded point. It can be different from the input point or geocode service.

Examples

C#

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

// Set reverse geocode search parameters

PropertySetProperty revGeocodeProp = new PropertySetProperty();

revGeocodeProp.Key = "ReverseDistanceUnits";

revGeocodeProp.Value = "Meters";

 

PropertySetProperty revGeocodeProp1 = new PropertySetProperty();

revGeocodeProp1.Key = "ReverseDistance";

revGeocodeProp1.Value = "100";

 

// Optionally define output spatial reference for reverse geocoded point

ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem();

projectedCoordinateSystem.WKID = 54004;

projectedCoordinateSystem.WKIDSpecified = true;

 

PropertySetProperty revGeocodeProp2 = new PropertySetProperty();

revGeocodeProp2.Key = "OutputSpatialReference";

revGeocodeProp2.Value = class=codesample>projectedCoordinateSystem;

PropertySetProperty[] propArray = new PropertySetProperty[] {revGeocodeProp, revGeocodeProp1, revGeocodeProp2 };

 

PropertySet revGeocodePropSet = new PropertySet();

revGeocodePropSet.PropertyArray = propArray;

 

// Create point to reverse geocode, define input spatial reference

PointN inputPoint = new PointN();

inputPoint.X = -117.391;

inputPoint.Y = 33.961;

 

GeographicCoordinateSystem geographicCoordinateSystem = new GeographicCoordinateSystem();

geographicCoordinateSystem.WKID = 4326;

geographicCoordinateSystem.WKIDSpecified = true;

inputPoint.SpatialReference = geographicCoordinateSystem;

 

// Reverse geocode

PropertySet results = geocodeservice.ReverseGeocode(inputPoint, false, revGeocodePropSet);// Iterate through results

PropertySetProperty[] resultsArray = results.PropertyArray;

 

// For each result, print address and matched point

foreach (PropertySetProperty result in resultsArray)

{

      System.Diagnostics.Debug.WriteLine(result.Key.ToString());

      if (result.Value is PointN)

      {

      PointN pn = (PointN)result.Value;

      System.Diagnostics.Debug.WriteLine(pn.X + ", " + pn.Y);

      }

      else

      {

      System.Diagnostics.Debug.WriteLine(result.Value.ToString());

      }

}

VB.NET

Dim geocodeservice As GeocodeService_GeocodeServer = New GeocodeService_GeocodeServer()

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer"

 

' Set reverse geocode search parameters

Dim revGeocodeProp As PropertySetProperty = New PropertySetProperty()

revGeocodeProp.Key = "ReverseDistanceUnits"

revGeocodeProp.Value = "Meters"

 

Dim revGeocodeProp1 As PropertySetProperty = New PropertySetProperty()

revGeocodeProp1.Key = "ReverseDistance"

revGeocodeProp1.Value = "100"

 

' Optionally define output spatial reference for reverse geocoded point

Dim projectedCoordinateSystem As ProjectedCoordinateSystem = New ProjectedCoordinateSystem()

projectedCoordinateSystem.WKID = 54004

projectedCoordinateSystem.WKIDSpecified = True

 

Dim revGeocodeProp2 As PropertySetProperty = New PropertySetProperty()

revGeocodeProp2.Key = "OutputSpatialReference"

revGeocodeProp2.Value = projectedCoordinateSystem

 

Dim propArray As PropertySetProperty() = New PropertySetProperty()

  {revGeocodeProp, revGeocodeProp1, revGeocodeProp2 }

 

Dim revGeocodePropSet As PropertySet = New PropertySet()

revGeocodePropSet.PropertyArray = propArray

 

' Create point to reverse geocode, define input spatial reference

Dim inputPoint As PointN = New PointN()

inputPoint.X = -117.391

inputPoint.Y = 33.961

 

Dim geographicCoordinateSystem As GeographicCoordinateSystem = New GeographicCoordinateSystem()

geographicCoordinateSystem.WKID = 4326

geographicCoordinateSystem.WKIDSpecified = True

 

inputPoint.SpatialReference = geographicCoordinateSystem

 

' Reverse geocode

Dim results As PropertySet = geocodeservice.ReverseGeocode(inputPoint, False, revGeocodePropSet)

 

' Iterate through results

Dim resultsArray As PropertySetProperty() = results.PropertyArray

 

' For each result, print address and matched point

For Each result As PropertySetProperty In resultsArray

      System.Diagnostics.Debug.WriteLine(result.Key.ToString())

      If TypeOf result.Value Is PointN Then

            Dim pn As PointN = CType(result.Value, PointN)

            System.Diagnostics.Debug.WriteLine(pn.X & ", " & pn.Y)

      Else

            System.Diagnostics.Debug.WriteLine(result.Value.ToString())

      End If

Next result

Java

String serviceURL = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

GeocodeServerBindingStub geocodeService = new GeocodeServerBindingStub(serviceURL);

 

//Set reverse geocode search parameters

PropertySetProperty revGeocodeProp1 = new PropertySetProperty();

revGeocodeProp1.setKey("ReverseDistanceUnits");

revGeocodeProp1.setValue("Meters");

 

PropertySetProperty revGeocodeProp2 = new PropertySetProperty();

revGeocodeProp2.setKey("ReverseDistance");

revGeocodeProp2.setValue("100");

 

//Optionally define output spatial reference for reverse geocoded point

ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem();

projectedCoordinateSystem.setWKID(54004);

PropertySetProperty revGeocodeProp3 = new PropertySetProperty();

revGeocodeProp3.setKey("OutputSpatialReference");

revGeocodeProp3.setValue(projectedCoordinateSystem);

PropertySetProperty[] propArray = new PropertySetProperty[] {

      revGeocodeProp1, revGeocodeProp2, revGeocodeProp3 };

PropertySet revGeocodePropSet = new PropertySet();

revGeocodePropSet.setPropertyArray(propArray);

 

//Create point to reverse geocode, define input spatial reference

GeographicCoordinateSystem geographicCoordinateSystem = new GeographicCoordinateSystem();

geographicCoordinateSystem.setWKID(4326);

 

double xCoord = -122.39649504;

double yCoord = 37.7931136;

 

PointN inputPoint = new PointN();

inputPoint.setX(xCoord);

inputPoint.setY(yCoord);

inputPoint.setSpatialReference(geographicCoordinateSystem);

 

//Reverse geocode

PropertySet results = geocodeService.reverseGeocode(inputPoint, false, revGeocodePropSet);

 

System.out.println("Results...");

 

PropertySetProperty[] pSetPropertyArray = results.getPropertyArray();

for (PropertySetProperty pSetArray : pSetPropertyArray) {

      String key = pSetArray.getKey();

      Object value = pSetArray.getValue();

      System.out.println(key + ": " + value);

}

2/28/2020