Appendix A: Scripts written for this project

The following scripts were written in Avenue, the scripting language of ArcView
version 2 (Environmental Systems Research Institute, Redlands, CA). To install
these pattern finding applications, copy these five scripts into your project
and create two new buttons in the View button bar called `Find Same' and `Blind
Pattern.' Select `View.FindSame.ave' as the script for the `Find Same' button
and `View.FindSameUpdate.ave' as the update script for the button. Select
`View.BlindPattern.ave' as the script for the `Blind Pattern' button. These
names may be shortened for a DOS-based operating system.

'********************************************************************

'View.BlindPattern.ave

'Raj Singh, 1996

theView = av.GetActiveDoc

theThemeList = theView.GetThemes

dontstop = true

usedThemeList = List.Make

while (dontstop = true)

'Have the user choose a theme

themeChoice = MsgBox.Choice (theThemeList,"Select a theme of interest","Theme Select (Cancel when done)")

usedThemeList = usedThemeList.Add(themeChoice)

'if the user hits cancel, then they are done and we send

'the list of used themes to the calling script

if (themeChoice = nil) then

dontstop = false

returnVal = av.Run ("FS.IntersectThemes",usedThemeList)

exit

end

'Have the user choose a field from the chosen theme

themeChoiceFTab = themeChoice.GetFTab

themeChoiceFieldList = themeChoiceFTab.GetFields

themeChoiceName = themeChoice.GetName

titleName = themeChoiceName+" Attribute Selection"

fieldChoice = MsgBox.Choice (themeChoiceFieldList, "Select a field of interest",titleName)

if (fieldChoice = nil) then

MsgBox.Error("No field chosen","")

exit

end

'get summary info, so far mean, maximum, minimum

fieldsum = 0

fieldmin = 0

fieldmax = 0

for each recno in themeChoiceFTab

fieldVal = themeChoiceFTab.ReturnValue(fieldChoice,recno)

if ( fieldVal >= 0 ) then

fieldsum = fieldsum + fieldVal

end

if ( fieldVal < fieldmin ) then

fieldmin = fieldVal

end

if ( fieldVal > fieldmax ) then

fieldmax = fieldVal

end

end

numrecs = themeChoiceFTab.GetNumRecords

fieldmean = fieldsum / numrecs

statString = "MAX="+fieldmax.AsString+" MEAN="+fieldmean.AsString+" MIN="+fieldmin.AsString

'shows the user min & max and asks for user min & max

minString = fieldChoice.GetAlias+" statistics: "+statString+"."+"What is the MINIMUM value you are interested in?"

maxString = fieldChoice.GetAlias+" statistics: "+statString+"."+"What is the MAXIMUM value you are interested in?"

minVal = MsgBox.Input(minString,"Minimum Value",fieldmean.AsString)

maxVal = MsgBox.Input(maxString,"Maximum Value",fieldmean.AsString)

'select all the objects that meet the requirements

queryStringy = "(["+fieldchoice.GetAlias+"]>="+minVal+") and (["+fieldChoice.GetAlias+"]<="+maxVal+")"

isOK = themeChoiceFTab.Query(queryStringy,themeChoiceFTab.GetSelection,#VTAB_SELTYPE_NE)

themeChoiceFTab.UpdateSelection

av.GetProject.SetModified(true)

end 'while

returnVal = av.Run ("FS.IntersectThemes",usedThemeList)

'********************************************************************

'View.FindSame.ave

'Raj Singh, 1996

'This script finds the values of the selected fields of selected

'themes which underly the selected polygon. Then based on those

'values, the user can expand their range a bit and find all other

'areas on the map that fall within the range of values chosen for the

'selected themes.

'

'the update script should make sure only one theme is active and

'only one polygon is selected when this script is called

theView = av.GetActiveDoc

theObjectTheme = av.GetActiveDoc.GetActiveThemes.Get(0)

theFTab = av.GetActiveDoc.GetActiveThemes.Get(0).GetFTab

themeFieldList = List.Make

theThemeList = theView.GetThemes

themeFieldList = themeFieldList.Empty

usedThemeList = av.Run ("FS.SelectThemes","")

usedCount = usedThemeList.Count

returnVal = av.Run ("FS.IntersectThemes",usedThemeList)

'********************************************************************

'FS.SelectThemes

'Raj Singh, 1996

'select objects from themes of interest

theView = av.GetActiveDoc

theObjectTheme = theView.GetActiveThemes.Get(0)

theThemeList = theView.GetThemes

dontstop = true

usedThemeList = List.Make

while (dontstop = true)

'Have the user choose a theme

themeChoice = MsgBox.Choice (theThemeList,"Select a theme of interest or Cancel to quit","External Theme Select")

usedThemeList = usedThemeList.Add(themeChoice)

'if the user hits cancel, then they are done and we send

'the list of used themes to the calling script

if (themeChoice = nil) then

dontstop = false

return usedThemeList

end

themeChoiceFTab = themeChoice.GetFTab

themeChoiceFieldList = themeChoiceFTab.GetFields

themeChoiceName = themeChoice.GetName

'Select the record of interest in this theme

themeChoice.SelectByTheme(theObjectTheme, #FTAB_RELTYPE_INTERSECTS, 0, #VTAB_SELTYPE_NEW)

av.GetProject.SetModified(true)

if (themeChoiceFTab.GetSelection.Count = 0) then

MsgBox.Error("The themes do not intersect","")

exit

end

'Have the user choose a field from the chosen theme

titleName = themeChoiceName+" Attribute Selection"

fieldChoice = MsgBox.Choice (themeChoiceFieldList, "Select a field of interest",titleName)

if (fieldChoice = nil) then

MsgBox.Error("No field chosen","")

exit

end

'gets the value for the chosen field & record

for each recno in themeChoiceFTab.GetSelection

fieldVal = themeChoiceFTab.ReturnValue(fieldChoice,recno) 'only one object selected, so only one record

end

'shows the user min & max and asks for user min & max

minString = fieldChoice.GetAlias+" equals "+fieldVal.AsString+" at the location of the object. What is the MINIMUM value you are interested in?"

maxString = fieldChoice.GetAlias+" equals "+fieldVal.AsString+" at the location of the object. What is the MAXIMUM value you are interested in?"

minVal = MsgBox.Input(minString,"Minimum Value",fieldVal.AsString)

maxVal = MsgBox.Input(maxString,"Maximum Value",fieldVal.AsString)

'select all the objects that meet the requirements

queryStringy = "(["+fieldchoice.GetAlias+"]>="+minVal+") and (["+fieldChoice.GetAlias+"]<="+maxVal+")"

isOK = themeChoiceFTab.Query(queryStringy,themeChoiceFTab.GetSelection,#VTAB_SELTYPE_NE)

themeChoiceFTab.UpdateSelection

av.GetProject.SetModified(true)

end 'while

return usedThemeList

'********************************************************************

'View.FindSameUpdate.ave

'Raj Singh, 1996

SELF.SetEnabled(false)

theView = av.GetActiveDoc

activeList = theView.GetActiveThemes

if (activeList.Count = 1) then

searchTheme = activeList.Get(0).GetFTab

if (searchTheme.GetSelection.Count > 0) then

SELF.SetEnabled(true)

end

end

'********************************************************************

'FS.IntersectThemes

'Raj Singh, 1996

'intersects selected objects in the used theme list

theView = av.GetActiveDoc

usedThemeList = SELF.AsList

usedCount = usedThemeList.Count

theTheme = usedThemeList.Get(0)

lastItem = usedCount - 1

usedThemeList.Remove(lastItem)

i = 1

while (i <= (lastItem - 1))

selectTheme = usedThemeList.Get(i)

theTheme.SelectByTheme(selectTheme, #FTAB_RELTYPE_INTERSECTS,0,#VTAB_SELTYPE_AND)

av.GetProject.SetModified(true)

i = i + 1

end 'while

if (File.Exists("xxselect.shp".AsFileName)) then

File.Delete("xxselect.shp".AsFileName)

end

if (theView.FindTheme("xxselect.shp") <> nil) then

theView.DeleteTheme(theView.FindTheme("xxselect.shp"))

end

newFTab = theTheme.GetFTab.Export("xxselect.shp".AsFileName, Shape,true)

theSrcName = SrcName.Make ("xxselect.shp")

if (theSrcName = nil) then

MsgBox.Error("invalid SrcName","")

exit

end

newTheme = Theme.Make(theSrcName)

newTheme.SetVisible(true)

theView.AddTheme(newTheme)

av.GetProject.SetModified(true)


Next section (Appendix B)