' This script is used for filling in missing values by taking ' the average of the neighbors. ' It creates a new VTab for the data. ' It was written by Timothy S. Thomas. ' Editing began on 7/25/00, and was last edited on 7/25/00. ' ********************************************************** ' Set up basic variables ' ********************************************************** ' This tells Arc/View that numerical output will be integer only. Script.The.SetNumberFormat("d.dd") theProject = av.GetProject theView = av.GetActiveDoc theThemeList = theView.GetActiveThemes theTheme = theThemeList.Get(0) theTheme.ClearSelection theFTab = theTheme.GetFTab numRecs = theFTab.GetNumRecords ' "Shape" is a special word in FTabs shapeField = theFTab.FindField("Shape") ' It is necessary to clone fields, otherwise changes are made ' to the FTab, with undesirable results. fieldList = theFTab.GetFields.Clone ' Permits changes to be made to the FTab theFTab.SetEditable(True) ' ********************************************************** ' This allows the user to pick a field as the basic unit for ' evaluation. ' ********************************************************** mainField = MsgBox.ChoiceAsString(fieldList, "Select field to interpolate missing values","Choose field") idField = MsgBox.ChoiceAsString(fieldList, "Select unique id","Choose field") idString = idField.AsString mainString = mainField.AsString FTabFN = theFTab.GetSrcName.GetFileName baseString = FTabFN.GetBaseName extString = FTabFN.GetExtension newString = FTabFN.AsString.Substitute(baseString,"") new2String = baseString.Substitute(extString,"dbf") theFN = FileDialog.Put( (newString + "Interpolated " + mainString).AsFileName, "*.dbf","Data file name") newidField = idField.Clone newmainField = mainField.Clone ktField = Field.Make("KtNbrs",#FIELD_SHORT ,8,0) outVTab = VTab.MakeNew(theFN,dBase) outVTab.AddFields({newidField,newmainField,ktField}) outVTab.SetEditable(True) ' ********************************************************** ' Find neighbors if missing a value ' ********************************************************** ' Shows message in message bar av.ShowMsg("Interpolating data") av.ShowStopButton addRadius = MsgBox.Input("What radius to add in map units?","Radius","0").AsNumber for each recnum in 0..(numRecs-1) newrec = recnum outVTab.AddRecord outVTab.SetValue(newidField,newrec,theFTab.ReturnValue(idField,recnum)) outVTab.SetValue(ktField,newrec,0) if (theFTab.ReturnValue(mainField,recnum).IsNull.Not) then outVTab.SetValue(newmainField,newrec,theFTab.ReturnValue(mainField,recnum)) else thePoly = theFTab.ReturnValue(shapeField,recnum) theRect = thePoly.ReturnExtent sizeX = theRect.ReturnSize.GetX sizeY = theRect.ReturnSize.GetY theCircle = Circle.Make(theRect.ReturnCenter, (((sizeX/2)^2) + ((sizeY/2)^2)).sqrt + addRadius) ktnbr = 0 sumnbr = 0 for each recnum2 in 0..(numrecs-1) aNeighbor = theCircle.Intersects(theFTab.ReturnValue(shapeField,recnum2)) if (aNeighbor = true) then if (theFTab.ReturnValue(mainField,recnum2).IsNull.Not) then ktnbr = ktnbr + 1 sumnbr = sumnbr + theFTab.ReturnValue(mainField,recnum2) end end end if (ktnbr = 0) then MsgBox.Info(theFTab.ReturnValue(mainField,recnum).AsString,"No Neighbors") else outVTab.SetValue(newmainField,newrec,(sumnbr/ktnbr)) outVTab.SetValue(ktField,newrec,ktnbr) end end av.SetStatus(100*recnum/(numrecs-1)) end ' Clears message in message bar av.ClearMsg ' Turns off editing in the FTab theFTab.SetEditable(false) ' Removes garbage objects av.PurgeObjects