VB.NET Display multiple Geosearch results

2296
12
Jump to solution
01-08-2013 06:46 AM
Corbinde_Bruin
Occasional Contributor II
I've written a GeocodeAddress method which is a modified version of the SDK vb.net FindAddress sample. I'm using a local address locator and I can't understand how to make it return multiple results. It is only returning the first result.

If I use the same locator in ArcMap's native Find tool, it pulls up a bunch of records.

All help is appreciated,
Corbin de Bruin

 Private Sub GeocodeAddress()         locatorManager = TryCast(obj, ILocatorManager2)         locatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath(gLocatorWorkspace)          Dim locator As ILocator = locatorWorkspace.GetLocator("Street_Addresses_US")          ' Set up the address properties         Dim addressInputs As IAddressInputs = TryCast(locator, IAddressInputs)         Dim addressFields As IFields = addressInputs.AddressFields         Dim addressProperties As IPropertySet = New PropertySetClass()         addressProperties.SetProperty(addressFields.Field(0).Name, txtAddress.Text)         addressProperties.SetProperty(addressFields.Field(1).Name, txtCity.Text)         addressProperties.SetProperty(addressFields.Field(2).Name, txtState.Text)         addressProperties.SetProperty(addressFields.Field(3).Name, txtZIP.Text)          ' Match the Address         Dim addressGeocoding As IAddressGeocoding = TryCast(locator, IAddressGeocoding)         Dim resultSet As IPropertySet = addressGeocoding.MatchAddress(addressProperties)          'Write results to DataGridView         Dim names, values As Object ' Not sure how these ever really get populated. They produce a warning where a null reference exception could be produced         resultSet.GetAllProperties(names, values)         Dim namesArray() As String = TryCast(names, String())         Dim valuesArray() As Object = TryCast(values, Object())         Dim length As Integer = namesArray.Length ' Not terribly sure what this line does.         Dim addressPoint As IPoint = Nothing         dgvAddrResults.Rows.Add() ' Create DataGridRow to hold result         For i As Integer = 0 To length - 1             Select Case namesArray(i) ' Case Statement to write proper fields to DataGrid Columns                 Case "Status"                     If valuesArray(i).ToString() = "U" Then                         lblAddressPrompt.Text = "***Address was not found."                         lblAddressPrompt.Visible = True                         Exit Sub                     End If                 Case "Shape"                     addressPoint = TryCast(valuesArray(i), IPoint)                     If addressPoint IsNot Nothing AndAlso (Not addressPoint.IsEmpty) Then                         dgvAddrResults.Item("Coordinates", 0).Value = addressPoint.X.ToString & ", " & addressPoint.Y.ToString                     Else                         dgvAddrResults.Item("Coordinates", 0).Value = "No geographic point available"                     End If                 Case "Score"                     dgvAddrResults.Item("Score", 0).Value = valuesArray(i).ToString()                 Case "Match_addr"                     dgvAddrResults.Item("Address", 0).Value = valuesArray(i).ToString()                 Case "Addr_type"                     dgvAddrResults.Item("Type", 0).Value = valuesArray(i).ToString()             End Select          Next i      End Sub
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
It's been a really, really long time since I've worked with address locators and I may be wrong but I don't think your code is doing what you think it's doing.  I believe the MatchAddress method is simply returning a property set that contains the geocoded address that you're trying to match.  In other words, you're passing in the address you want to match ("search for" might be a better description) in pieces and it puts them together into the standardized format defined by the locator you're using.  If you want the actual results of the search then I think you need to be using the IAddressCandidates interface and calling the FindAddressCandidates method.

View solution in original post

0 Kudos
12 Replies
MichaelVolz
Esteemed Contributor
Can you put in any variable trapping to see what the length variable is set to when running this code?
0 Kudos
Corbinde_Bruin
Occasional Contributor II
Mike,

The 'length' variable is actually looping through the fields in the row. That's the horizontal aspect of the database which I have working correctly. I don't have the verticle aspect of the database. I don't see the capacity for it using this method either.

I could post the sample FindAddress code from the SDK if that would help.
0 Kudos
MichaelVolz
Esteemed Contributor
Is the resultSet supposed to be all the records that have matched your geocode parameters?  If so, can you tell what the count is for this object?  Maybe something like resultSet.GetCount, but I'm not sure that is even a parameter for the resultSet object.
0 Kudos
Corbinde_Bruin
Occasional Contributor II
Debug.Print("resultSet.Count = " & resultSet.Count)

The count is seven which is actually the same as 'length'. I see 'resultSet' is some kind of properties item:
Dim resultSet As IPropertySet = addressGeocoding.MatchAddress(addressProperties)

It looks like 'length is just another way of saying 'resultSet.Count':
Dim length As Integer = namesArray.Length ' Not terribly sure what this line does. Probably does the same thing as resultSet.Count
0 Kudos
MichaelVolz
Esteemed Contributor
I could post the sample FindAddress code from the SDK if that would help.

Can you please post this code or provide the link to the location where the code is found?
0 Kudos
Corbinde_Bruin
Occasional Contributor II
Some differences are:

  • I'm displaying the data in a DataGridView, not a RichTextBox

  • I'm specifying which column to enter each field, and only the fields I want.

I found this here:
C:\Program Files (x86)\ArcGIS\DeveloperKit10.1\Samples\ArcObjectsNet\FindAddress\VBNet\FindAddress2010.sln
Private Sub GeocodeAddress()
      ' Get the locator
      Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
      Dim locatorManager As ILocatorManager2 = TryCast(obj, ILocatorManager2)
      Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath("C:\locators")
      Dim locator As ILocator = locatorWorkspace.GetLocator("California_city_state_zip")

      ' Set up the address properties
      Dim addressInputs As IAddressInputs = TryCast(locator, IAddressInputs)
      Dim addressFields As IFields = addressInputs.AddressFields
      Dim addressProperties As IPropertySet = New PropertySetClass()
      addressProperties.SetProperty(addressFields.Field(0).Name, Me.AddressTextBox.Text)
      addressProperties.SetProperty(addressFields.Field(1).Name, Me.CityTextBox.Text)
      addressProperties.SetProperty(addressFields.Field(2).Name, Me.StateTextBox.Text)
      addressProperties.SetProperty(addressFields.Field(3).Name, Me.ZipTextBox.Text)

      ' Match the Address
      Dim addressGeocoding As IAddressGeocoding = TryCast(locator, IAddressGeocoding)
      Dim resultSet As IPropertySet = addressGeocoding.MatchAddress(addressProperties)

      ' Print out the results
      Dim names, values As Object
      resultSet.GetAllProperties(names, values)
      Dim namesArray() As String = TryCast(names, String())
      Dim valuesArray() As Object = TryCast(values, Object())
      Dim length As Integer = namesArray.Length
      Dim point As IPoint = Nothing
      For i As Integer = 0 To length - 1
        If namesArray(i) <> "Shape" Then
          Me.ResultsTextBox.Text += namesArray(i) & ": " & valuesArray(i).ToString() & Constants.vbLf
        Else
          If point IsNot Nothing AndAlso (Not point.IsEmpty) Then
            point = TryCast(valuesArray(i), IPoint)
            Me.ResultsTextBox.Text &= "X: " & point.X + Constants.vbLf
            Me.ResultsTextBox.Text &= "Y: " & point.Y + Constants.vbLf
          End If
        End If
      Next i

      Me.ResultsTextBox.Text += Constants.vbLf
    End Sub
0 Kudos
MichaelVolz
Esteemed Contributor
Have you tried compiling ESRI's sample to see if it returns multiple results?
0 Kudos
Corbinde_Bruin
Occasional Contributor II
I have complied it. It does not return multiple results. It's only available to be used as a starting point, and it doesn't take you very far.
0 Kudos
NeilClemmons
Regular Contributor III
It's been a really, really long time since I've worked with address locators and I may be wrong but I don't think your code is doing what you think it's doing.  I believe the MatchAddress method is simply returning a property set that contains the geocoded address that you're trying to match.  In other words, you're passing in the address you want to match ("search for" might be a better description) in pieces and it puts them together into the standardized format defined by the locator you're using.  If you want the actual results of the search then I think you need to be using the IAddressCandidates interface and calling the FindAddressCandidates method.
0 Kudos