ESRI.ArcGIS.ADF.IMS
AddressValueCollection Class
Members  Example  See Also 
ESRI.ArcGIS.ADF.IMS.Geocode Namespace : AddressValueCollection Class




A thread-safe collection of AddressValues.

Object Model

Syntax

Visual Basic (Declaration) 
<DefaultMemberAttribute("Item")>
<SerializableAttribute()>
Public Class AddressValueCollection 
   Inherits ThreadSafeCollection
Visual Basic (Usage)Copy Code
Dim instance As AddressValueCollection
C# 
[DefaultMemberAttribute("Item")]
[SerializableAttribute()]
public class AddressValueCollection : ThreadSafeCollection 

Example

This example geocodes an address and displays the results in a standard .NET GridView control. Prior to geocoding, the minimum score and maximum candidates are changed from their defaults, and the AddressValueCollection is built by adding AddressValue items based on field input names ("STREET", etc.; these can be obtained from the InputFieldCollection of the Geocoder object). Geocoding returns the results as a FeatureTable. Since the shape field is a point object, it will not display by default in a GridView, so here we add X and Y columns and copy the point's coordinate values into these columns. The point coordinates will then display in the GridView.
C#Copy Code
// Address to geocode 

string address = "98 S 2nd St"; 

string zone = "95113"; 

  

ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer streetLayer = 

    (ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer) mapView.Layers["2"]; 

  

// Get the Geocoder from the FeatureLayer 

ESRI.ArcGIS.ADF.IMS.Geocode.Geocoder streetGeocoder = streetLayer.Geocoder; 

  

if (streetGeocoder != null) 



    // Set mininum score and maximum candidates 

    streetGeocoder.MinScore = 30; 

    streetGeocoder.MaxCandidates = 5; 

  

    ESRI.ArcGIS.ADF.IMS.Geocode.AddressValueCollection valColl 

        = new ESRI.ArcGIS.ADF.IMS.Geocode.AddressValueCollection(); 

    ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue addrVal; 

  

    // Add geocoding values to value collection (can get FieldID from InputField) 

    addrVal = new ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue("STREET", address); 

    valColl.Add(addrVal); 

    addrVal = new ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue("ZONE", zone); 

    valColl.Add(addrVal); 

  

    // Do geocoding with the value collection 

    ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureTable geocodeResults 

        = streetGeocoder.Geocode(valColl); 

  

    if (geocodeResults.Rows.Count > 0) 

    { 

        // Add x and y fields to the feature table 

        DataColumn xCol = new DataColumn("X", typeof(Double)); 

        DataColumn yCol = new DataColumn("Y", typeof(Double)); 

        geocodeResults.Columns.Add(xCol); 

        geocodeResults.Columns.Add(yCol); 

  

        ESRI.ArcGIS.ADF.IMS.Geometry.Point pt; 

  

        // Copy the x and y values from the point geometry to the x/y fields 

        foreach (DataRow row in geocodeResults.Rows) 

        { 

            pt = (ESRI.ArcGIS.ADF.IMS.Geometry.Point)row["#SHAPE#"]; 

            row["X"] = pt.X; 

            row["Y"] = pt.Y; 

        } 

         

        GridView1.DataSource = geocodeResults; 

        GridView1.DataBind(); 

    } 

    else 

        Label1.Text = "No matching locations found for the address."; 



    
Visual BasicCopy Code
' Address to geocode

Dim address As String = "98 S 2nd St"

Dim zone As String = "95113"



Dim streetLayer As ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer = _

    CType(mapView.Layers("2"), _

    ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer)



' Get the Geocoder from the FeatureLayer

Dim streetGeocoder As ESRI.ArcGIS.ADF.IMS.Geocode.Geocoder _

    = streetLayer.Geocoder



If Not IsNothing(streetGeocoder) Then



    ' Set mininum score and maximum candidates

    streetGeocoder.MinScore = 30

    streetGeocoder.MaxCandidates = 5



    Dim valColl As New ESRI.ArcGIS.ADF.IMS.Geocode.AddressValueCollection()

    Dim addrVal As ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue addrVal



    ' Add geocoding values to value collection (can get FieldID from InputField)

    addrVal = New ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue("STREET", address)

    valColl.Add(addrVal)

    addrVal = New ESRI.ArcGIS.ADF.IMS.Geocode.AddressValue("ZONE", zone)

    valColl.Add(addrVal)



    ' Do geocoding with the value collection

    Dim geocodeResults As ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureTable _

        = streetGeocoder.Geocode(valColl)



    If geocodeResults.Rows.Count > 0 Then



        ' Add x and y fields to the feature table

        Dim xCol As New DataColumn("X", GetType(Double))

        Dim yCol As New DataColumn("Y", GetType(Double))

        geocodeResults.Columns.Add(xCol)

        geocodeResults.Columns.Add(yCol)



        Dim pt As ESRI.ArcGIS.ADF.IMS.Geometry.Point



        ' Copy the x and y values from the point geometry to the x/y fields

        For Each row As DataRow In geocodeResults.Rows



            pt = CType(row("#SHAPE#"), ESRI.ArcGIS.ADF.IMS.Geometry.Point)

            row("X") = pt.X

            row("Y") = pt.Y

        Next row



        GridView1.DataSource = geocodeResults

        GridView1.DataBind()



    Else

        Label1.Text = "No matching locations found for the address."

    End If

End If

Remarks

Geocoding is performed by creating an AddressValueCollection and sending it to the server by the Geocode method of Geocoder.

Inheritance Hierarchy

System.Object
   ESRI.ArcGIS.ADF.ThreadSafeCollection
      ESRI.ArcGIS.ADF.IMS.Geocode.AddressValueCollection

See Also

© 2010 All Rights Reserved.