' Read Grids by Points ' This script is used for extracting grid values based on a point ' theme. ' It calls UniqIDScript, which means that until there is a Tim ' extension, one must actually have a compiled script based on ' UniqIDScript.ave, and in Script Propertied, must name the script ' UniqIDScript. ' It was written by Timothy S. Thomas. ' Editing began on 12/6/99, and was last edited on 12/7/99. ' ********************************************************** ' Set up basic variables ' ********************************************************** ' This tells Arc/View that numerical output will be integer only. ' If we wanted decimal places, we would use something like ' "d.dd" Script.The.SetNumberFormat("d") theProject = av.GetProject theView = av.GetActiveDoc theThemeList = theView.GetActiveThemes theTheme = theThemeList.Get(0) theFTab = theTheme.GetFTab numRecs = theFTab.GetNumRecords ' "Shape" is a special word in FTabs shapeField = theFTab.FindField("Shape") ' Permits changes to be made to the FTab theFTab.SetEditable(True) ' ********************************************************** ' Establish unique polygon id ' ********************************************************** idField = av.Run("UniqIDScript",{theFTab}) ' ********************************************************** ' Make a DBF file (VTab) to hold values from grid ' ********************************************************** ' Choose filename to save extracted data to newidField = idField.Clone ' MsgBox.Info(FileName.GetCWD.AsString,"") theFN = FileDialog.Put((FileName.GetCWD.AsString + "temp.dbf").AsFileName, "*.dbf","Data file name") dataVTab = VTab.MakeNew(theFN,dBase) dataVTab.AddFields({newidField}) ' Choose which view to extract data from themeList = List.Make for each thm in theView.GetThemes if (thm.Is(GTheme)) then themeList.Add(thm) end end if (themeList.Count = 0) then MsgBox.Warning("No grid themes in view","") Exit end nullPrj = Prj.MakeNull kt = 0 while (kt < 100) gridTheme = MsgBox.ChoiceAsString(themeList, "Select grid theme from which to extract data", "Select grid theme") theGrid = gridTheme.GetGrid intBool = theGrid.IsInteger statList = theGrid.GetStatistics chars = ((statList.Get(0).abs)Max(statList.Get(1).abs)).log(10).floor if (chars < 0) then fldLen = chars.abs + 5 fldDec = chars.abs + 2 else fldLen = chars.abs + 5 fldDec = 3 end fldString = MsgBox.Input("Type name for variable (8 characters)", "Variable Name",GridTheme.AsString.Left(8)) if (intBool = true) then newField = Field.Make(fldString,#FIELD_LONG,chars+1,0) else newField = Field.Make(fldString,#FIELD_DOUBLE,fldLen,fldDec) end dataVTab.AddFields({newField}) if (kt = 0) then ' Shows message in message bar av.ShowMsg("Adding data to DBF file") for each rec in theFTab outrec = dataVTab.AddRecord thePoint = theFTab.ReturnValue(shapeField,rec) dataVTab.SetValue(newidField,outrec,theFTab.ReturnValue(idField,rec)) if (intBool = true) then dataVTab.SetValue(newField,outrec,theGrid.CellValue(thePoint,nullPrj)) else dataVTab.SetValue(newField,outrec,theGrid.PointValue(thePoint,nullPrj)) end av.SetStatus(100*(rec+1)/numRecs) end ' Clears message in message bar av.ClearMsg ' Refresh updates the in-memory version of the FTab theFTab.Refresh else ' Shows message in message bar av.ShowMsg("Adding data to DBF file") for each rec in theFTab thePoint = theFTab.ReturnValue(shapeField,rec) if (intBool = true) then dataVTab.SetValue(newField,rec,theGrid.CellValue(thePoint,nullPrj)) else dataVTab.SetValue(newField,rec,theGrid.PointValue(thePoint,nullPrj)) end av.SetStatus(100*(rec+1)/numRecs) end ' Clears message in message bar av.ClearMsg ' Refresh updates the in-memory version of the FTab theFTab.Refresh end if (MsgBox.YesNo("Do you want to extract more data?","More Data?",true)) then kt = 1 else kt = 101 end end removeList = List.Make for each d in theProject.GetDocs if (d.AsString = "Extracted Data" and d.Is(Table)) then removeList.Add(d) end end for each d in removeList theProject.RemoveDoc(d) end dataTable = Table.Make(dataVTab) dataTableWin = dataTable.GetWin dataTableWin.Open dataTable.SetName("Extracted Data") theFTable = theTheme.EditTable ' Join DBF file to FTab theFTab.Join(idField, dataVTab, newidField) ' Turns off editing theFTab.SetEditable(false) dataVTab.SetEditable(false) dataTableWin.Close ' Removes garbage objects av.PurgeObjects