Select to view content in your preferred language

Address Locator returns nothing in FindAddress2008 sample - ArcGIS 10

1427
9
07-16-2010 11:01 AM
MelodyMeinhardt
Deactivated User
From ArcCatalog I created an address locator, style 'US Address - Dual Ranges'.  My locator fields includes definitions for Left/Right City, Zip and State.

From ArcMap I bring up the find, specifiy that locator, and geocode an address - without a city, state, or zip - that brings back 2 results.

When I attempt to use the same address locator in the FindAddress2008 sample it does not return any results for the same address unless I specify a city.

What am I doing wrong? 

Initialization:

            ' Get the locator
            obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
            locatorManager = TryCast(obj, ILocatorManager2)
            locatorWorkspace = TryCast(locatorManager.GetLocatorWorkspaceFromPath("C:\Maps\HillsboroughRoute\Hills_poly_gdb.gdb"), ILocatorWorkspace2)
            locator = TryCast(locatorWorkspace.GetLocator("Hillsborough_USStreets"), ILocator2)

This is the code from GeocodeAddress:

      Private Sub GeocodeAddress()
            Me.ResultsTextBox.Text = String.Empty
            txtStopWatch.Text = String.Empty

            _stopWatch.Reset()
            _stopWatch.Start()

            ' Set up the address properties
            Dim addressInputs As IAddressInputs = TryCast(locator, IAddressInputs)
            Dim addressFields As IFields = addressInputs.AddressFields
            Dim addressProperties As IPropertySet2 = New PropertySetClass()
            Dim arrayFieldName As Object = Nothing

            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)

            Dim addressCandidates As ESRI.ArcGIS.Location.IAddressCandidates2 = TryCast(locator, IAddressCandidates2)
            Dim simpleArray As IArray = addressCandidates.FindMatchingAddressCandidates(addressProperties)
            Dim memberFields As IFields2
            Dim candidatePropertySet As IPropertySet2
            Dim values As Object = Nothing

            ' Print out the results
            If simpleArray.Count > 0 Then
                memberFields = TryCast(addressCandidates.CandidateFields, IFields2)
                candidatePropertySet = TryCast(simpleArray.Element(0), IPropertySet2)
                If candidatePropertySet.Count > 0 Then
                    Try
                        Dim matchAddr As String = String.Empty
                        Dim cnt As Integer = 1
                        For matchFieldIndex As Integer = 0 To simpleArray.Count - 1
                            Me.ResultsTextBox.Text &= "Count " & cnt & " "
                            candidatePropertySet = TryCast(simpleArray.Element(matchFieldIndex), IPropertySet2)
                            If Not candidatePropertySet Is Nothing AndAlso candidatePropertySet.Count > 0 Then
                                ' different locators may not have the same properties
                                candidatePropertySet.GetAllProperties(arrayFieldName, values)
                                Dim nArray As String() = TryCast(arrayFieldName, String())
                                Dim vArray As Object() = TryCast(values, Object())
                                Dim lgth As Integer = nArray.Length
                                Dim pt As IPoint = Nothing
                                Dim i As Integer = 0
                                Do While i < lgth
                                    If nArray(i) <> "Shape" Then
                                        Me.ResultsTextBox.Text += nArray(i) & ": " & vArray(i).ToString() & Constants.vbLf
                                    Else
                                        If Not pt Is Nothing AndAlso (Not pt.IsEmpty) Then
                                            pt = TryCast(vArray(i), IPoint)
                                            Me.ResultsTextBox.Text &= "X: " & pt.X + Constants.vbLf
                                            Me.ResultsTextBox.Text &= "Y: " & pt.Y + Constants.vbLf
                                        End If
                                    End If
                                    i += 1
                                Loop
                            End If
                            Me.ResultsTextBox.Text &= Constants.vbLf
                            cnt += 1

                        Next
                    Catch ex As Exception
                        Debug.Print(ex.Message)
                    End Try
                End If
            End If

            Me.ResultsTextBox.Text &= Constants.vbLf

            Dim names 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

            txtStopWatch.Text = "Time to process: " & _stopWatch.Elapsed.ToString
            _stopWatch.Stop()

        End Sub
0 Kudos
9 Replies
BradNiemand
Esri Regular Contributor
Explaination:
The way that the FindAddress SDK sample works is that it uses the IAddressInputs interface to determine what the address input fields are supposed to be.  The was/is the way to determine the address input fields for multiline geocoding.

At 9.3 and at 10, a the US Streets with City State and Zip and US Address - Dual Ranges style both work the same way.  They expect that the use will enter either the city and state or the zip.  Without entering one or more of the "Zones" will not return a geocoded address.

At 10 we added a new interface named ISingleLineAddressInput that can be used to determine if 1. the locator supports single line entry and 2. to determine what the single line address field name is.  The find dialog and the geocoding toolbar both try to use the ISingleLineAddressInput if the locator supports it and will only use Multiline input if the locator does not support it.

Work Around:
1. Enter the address with either city and state or zip and the address will be found.
2. Use the ISingleLineAddressInput interface to determine the address input field and create a property set with that field name as the name, i.e. FullAddress, and your full street address as the value, "380 new york st redlands ca".  You can look at the sample "Single Line Address Geocoding" here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Single_line_addr...
0 Kudos
MelodyMeinhardt
Deactivated User
Thank you for the response!

Using the Dual Range address locator from ArcMap returns a candidate with a score of 100 without the user entering a city. Engine should work the same.  Sounds like a bug to me.
0 Kudos
BradNiemand
Esri Regular Contributor
It is not a bug, it is as designed. Let me see if I can explain it in a clearer way.

Single Line Input (i.e. Find Dialog, Geocoding Toolbar, Engine apps that use ISingleLineAddressInput to determine the address Input field):
  1. You may enter the address without zone information

Multiline Input (i.e. Batch Geocoding, Engine apps that use IAddressInputs to determine the address input fields, and the FindAddress2008 sample):
  1. You must enter the street as well as either the city and state or the zip (This functions exactly how it did with 9.3 locators but now 10 locators will not dock the score if the zip or city and state are not entered).

I will post an updated version of the sample in a while.
0 Kudos
BradNiemand
Esri Regular Contributor
I have now attached the updated version of the Sample.  It now functions almost exactly like the Find Dialog.  Let me know if you have any other questions.
0 Kudos
MelodyMeinhardt
Deactivated User
I tried to down load the zip file and then tried to just open the zip file and received a message 'Cannot open file; it does not appear to be a valid archive.'.
0 Kudos
BradNiemand
Esri Regular Contributor
I tried to download it on all of my machines and had no issue unzipping it.  What OS are you on?
0 Kudos
MelodyMeinhardt
Deactivated User
Brad, I am on XP Professional, SP 3. I tried a couple of different ways to open the zip and this is one of the messages I am getting:  End-of-central-directory signature not found.  Either this file is not a Zip file, or it constitutes one disk of a multi-part Zip file.
0 Kudos
BradNiemand
Esri Regular Contributor
Are you using the standard Windows Unzip or a different tool?  I have tried it on Windows 7 and on Windows XP SP3 and it works fine on those.  I have attached the updated files (I had to rename them to .txt from .vb in order to upload them).
0 Kudos
MelodyMeinhardt
Deactivated User
Thank  you very much for your assistance!  ISingleLineAddressInput works as we need it to.
0 Kudos