English

How To: Use ArcView geocoding functions to locate addresses

Summary

The View.Locate address finding function is fairly rigid in operation, it only accepts the highest score. The code in this article will allow you to pick an address match based on a list of possible matches.

Procedure

This code reconstructs the geocoding process but bypasses the normal geocoding interface.

  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the following code into the script window:

    Code:
    '-- Script: ModLocat.ave

    '-- This script allows you to modify the operation normally handled
    '-- by the View.Locate script. It asks for an input address and
    '-- searches for candidates. If no candidates are found, the
    '-- user is told and the process is safely stopped. If there is
    '-- one candidate found, the point is located and placed on the
    '-- view. If there are more candidates found, the user is given a
    '-- choice to pick one. The number of the chosen candidate is
    '-- sent back to the MatchCase object, to pull out the correct
    '-- candidate. A point is the located and placed on the view.

    '-- Prepare the geocoding scenario
    theView = av.GetActiveDoc
    theGL=theView.GetGraphics
    theTheme = theView.FindTheme("Streets")
    input = msgbox.Multiinput("Enter an address: ", "Input",
    {"House Number: ", "Street Name: "}, {"", ""})
    if (input = nil) then
    exit
    end

    hsenumber = input.get(0)
    name = input.get(1)
    addrinput = hsenumber++name
    msgbox.info(addrinput, "Is this the address?")

    aMatchSource = theTheme.GetMatchSource
    aMatchSource.OpenIndex
    aMatchKey = Matchkey.Make("us_addr.stn")
    aMatchKey.AllowIntersections("us_intsc.stn", "&")
    aMatchCase = MatchCase.Make(aMatchSource, aMatchKey)
    aMatchCase.AllowIntersections(aMatchSource, aMatchKey)

    '-- Match the user-input address to the GBF
    aMatchKey.SetKey(addrinput)
    numcand = aMatchSource.Search(aMatchKey, 80, aMatchCase)

    '-- If there are no candidates
    if (numCand = 0) then
    msgbox.info("Cannot locate address"+NL+"No candidates","")
    exit
    end

    '-- If there is only one candidate
    if (numCand = 1) then
    aMatchCase.ScoreCandidates
    cand = aMatchCase.GetBestCand
    thePt=aMatchSource.GetPoint(cand)
    theGPt=GraphicShape.Make(thePt)
    theGL.Add(theGPt)
    theView.Invalidate
    exit
    end

    '-- If there is more than 1 candidate
    addrList = {}
    if (numCand > 1) then
    aMatchCase.ScoreCandidates
    msgbox.info(numCand.asstring, "This is the number of candidates")
    for each int in 1..numCand
    cand = aMatchCase.getnthCand(int)
    addrstr = cand.GetValue(aMatchSource.GetMatchFields.Get(4))
    addrstr2 = cand.GetValue(aMatchSource.GetMatchFields.Get(5))
    addrstr4 = cand.GetValue(aMatchSource.GetMatchFields.Get(6))
    addrstr6 = cand.GetValue(aMatchSource.GetMatchFields.Get(7))
    'addrinfo = addrstr.trim++addrstr2.trim++addrstr4.trim++addrstr6.trim++int.asstring
    addrinfo = addrstr2.trim++int.asstring++cand.getscore.asstring
    addrList.Add(addrinfo)
    end

    theChosenAddrRaw = msgbox.ListAsString(addrList, "Choose one of the following:",
    "Select which address you want to be the match")
    theCandNumber=theChosenAddrRaw.extract(theChosenAddrRaw.Aslist.Count - 2).asnumber
    theFinalCand = aMatchCase.getnthCand(theCandNumber)
    thePt=aMatchSource.GetPoint(theFinalCand)
    theGPt=GraphicShape.Make(thePt)
    theGL.Add(theGPt)
    theView.Invalidate
    end

  3. Use the Theme Properties dialog box to rename the geocodable theme (the streets layer) to be Streets.
  4. Make the view active document.
  5. Click the script window and compile the script by clicking the
    [O-Image] Script compile button
    button.
  6. Click the
    [O-Image] Run compiled script button
    button to run the script.