'View.ZoneLocate
'
'Accept an address from the user, including a zone. The
'candidate matches have their potential zones checked
'against user input. A candidate with given zone agreeing
'with a member of the candidate's potential zones (from its
'list of fuzzy zones) becomes the selected candidate.
'
'Bruce Harold, Eagle Technology, November 1995
'
theView = av.GetActiveDoc
roadTheme = theView.FindTheme("Road")
roadFTab = roadTheme.GetFTab
routeFTab = FTab.Make((roadFTab.GetSrcname.GetDataSource++"route.sbrb").AsSrcName)
theMatchSource = roadTheme.GetMatchSource
theMFields = theMatchSource.GetMatchFields
theMatchSource.SetOffset(0) 'default is 10m
theMatchSource.OpenIndex
theMatchKey = MatchKey.Make(theMatchSource.GetStanRules)
theMatchKey.AllowIntersections(theMatchSource.GetStanRules,"&")
subMatchKey = MatchKey.Make("nzplaces.stn")
nfields = theMatchKey.GetNumFields - 1
theMatchKey.AllowIntersections("nz_intsc.stn","&")
theMatchCase = MatchCase.Make(theMatchSource,theMatchKey)
theMatchCase.AllowIntersections(theMatchSource,theMatchKey)
theDefaults = {"10 Beach Rd","Milford"}
theLabels = {"Address","Suburb"}
anAddressList = MsgBox
.MultiInput("Enter Address with Zone (= ""None"" if unknown)",
"Locate with Zone",theLabels,theDefaults)
if (anAddressList.Count = 0) then exit end
anAddress = anAddressList.Get(0)
aSuburb = anAddressList.Get(1)
if ((anAddress.Substitute(" ","").IsNull) or
(aSuburb.Substitute(" ","")).IsNull) then
MsgBox.Error("You must enter values for Address and Zone.","Exiting")
exit
end
theMatchKey.SetKey(anAddress)
subMatchKey.SetKey(aSuburb)
'
stanAddress = ""
for each i in 0..(nfields - 2) 'ignore soundex fields
stanAddress = stanAddress++theMatchKey
.GetValue(theMatchKey.GetNthField(i))++""
end
stanAddress = stanAddress.Trim.Proper
numCands = theMatchSource.Search(theMatchKey,75,theMatchCase)
if (theMatchCase.GetNumCands = 0) then
MsgBox.Error("No Candidates for"+nl++stanAddress,
"Bad Luck")
exit
end
'
stanSuburb = subMatchKey.GetValue(subMatchKey.GetNthField(0))
if (stanSuburb <> "") then
stanSuburb = stanSuburb.Proper
end
'
theMatchCase.ScoreCandidates
'
'Get the list of equal best candidates
bestscore = theMatchCase.GetBestCand.GetScore
candList = {}
for each c in 1..theMatchCase.GetNumCands
if (theMatchcase.GetNthCand(c).GetScore = bestscore) then
candList.Add(theMatchcase.GetNthCand(c))
end
end
'
'If many with best score see if one has a good Zone value.
favCand = nil
candSubList = {}
for each c in candList
arcrec = c.GetMatchSourceRec
zoneList = roadFtab.ReturnValue(roadFTab.FindField("Zonelist"),arcrec).Trim
.AsTokens(" ")
candSubList.Add(routeFtab.ReturnValue(routeFTab.FindField("Name"),(zoneList.Get(0).AsNumber)-1))
'candSubList.Add(routeFtab.ReturnValue(routeFTab.FindField("Name"),z.AsNumber-1)).AsNumber))
for each z in zoneList
if (routeFtab.ReturnValue(routeFTab.FindField("Name"),z.AsNumber-1)
.Substitute(" ","") = stanSuburb) then
favCand = c
end
end
end
'
'Use the favourite Candidate if found
if (favCand.Is(MatchCand)) then
thePoint = theMatchSource.GetPoint(favCand)
theGP = GraphicShape.Make(thePoint)
theView.GetGraphics.Add(theGP)
if ((thePoint.IsContainedIn(theView.GetDisplay.ReturnExtent)).Not) then
theView.GetDisplay.PanTo(thePoint)
end
exit
else 'Get the user to select a Candidate:
'Add graphics for each candidate
theGraphics = theView.GetGraphics
theGraphics.Empty
candRecList = {}
for each c in candList
candRecList.Add(c.GetMatchSourceRec)
candPoint = theMatchSource.GetPoint(c)
cGP = GraphicShape.Make(candPoint)
cGP.SetSymbol(av.GetSymbolWin.ReturnCurrentSymbol(#symbol_marker))
theGraphics.Add(cGP)
'cGT = GraphicText.Make(c.GetMatchSourceRec.AsString,candPoint)
cGT = GraphicText.Make(candSubList.Get(candList.Find(c)),candPoint)
cGT.SetSymbol(av.GetSymbolWin.ReturnCurrentSymbol(#symbol_text))
theGraphics.Add(cGT)
end
'
'Choose a candidate by inspection, or Cancel to bail
theChosenCand = candRecList
.Get(candSubList.Find(MsgBox.ListAsString(candSubList,"Choose the Suburb",stanAddress)))
'theChosenCand = MsgBox.ListAsString(candRecList,"Choose a Candidate",
' stanAddress++stanSuburb++"Candidates")
theGraphics.Empty
if (theChosenCand = nil) then
exit
end
for each c in candList
if (c.GetMatchSourceRec = theChosenCand) then
theChosenCand = c
end
end
if (theChosenCand.Is(MatchCand)) then
thePoint = theMatchSource.GetPoint(theChosenCand)
theGP = GraphicShape.Make(thePoint)
theView.GetGraphics.Add(theGP)
if ((thePoint.IsContainedIn(theView.GetDisplay.ReturnExtent)).Not) then
theView.GetDisplay.PanTo(thePoint)
end
end
end