' Read Polys by Points ' This script is used for extracting field values from a polygon ' theme using points from 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 Properties, must name the script ' UniqIDScript. ' It was written by Timothy S. Thomas. ' Editing began on 5/3/01, and was last edited on 5/3/01. ' It uses the basic structure of Read Grids by Point 2.ave, and ' borrows the selection process built into Fast Neighbors.ave, and ' also borrows the reading and writing of fields from one DBF to ' another built into Subtract Theme.ave. ' ********************************************************** ' Set up basic variables ' ********************************************************** 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") ' ********************************************************** ' Establish unique polygon id ' ********************************************************** idField = av.Run("UniqIDScript",{theFTab}) ' Permits changes to be made to the FTab theFTab.SetEditable(True) newidField = idField.Clone ' ********************************************************** ' Make a DBF file (VTab) to hold values from grid ' ********************************************************** ' Choose filename to save extracted data to ' MsgBox.Info(FileName.GetCWD.AsString,"") theFN = FileDialog.Put((FileName.GetCWD.AsString + "temp.dbf").AsFileName, "*.dbf","Data file name") dataVTab = VTab.MakeNew(theFN,dBase) ' Choose which view to extract data from themeList = List.Make for each thm in theView.GetThemes if (thm.Is(FTheme)) then if (thm.GetFTab.GetShapeClass.GetClassName = "Polygon") then themeList.Add(thm) end end end if (themeList.Count = 0) then MsgBox.Warning("No polygon themes in view","") Exit end polyTheme = MsgBox.ChoiceAsString(themeList, "Select polygon theme from which to extract data", "Select polygon theme") polyFTab = polyTheme.GetFTab ' Clone fields for dataVTab inFieldList = polyFTab.GetFields menuFieldList = List.Make for each f in inFieldList if (f.GetName <> "shape") then menuFieldList.Add(f.Clone) end end newFieldList = MsgBox.MultiListAsString(menuFieldList, "Select fields for output dataset", "Select Fields") dataVTab.AddFields({newidField}) dataVTab.AddFields(newFieldList) for each recnum in 0..(numRecs-1) thePoint = theFTab.ReturnValue(shapeField,recnum) polyFTab.SelectByPoint(thePoint,0.0000001,#VTAB_SELTYPE_NEW) for each s in polyFTab.GetSelection newrec = dataVTab.AddRecord dataVTab.SetValue(newidField,newrec,theFTab.ReturnValue(idField,recnum)) for each fld in dataVTab.GetFields fldName = fld.GetName if ((fld <> newidField) and(fldName <> "shape")) then infld = polyFTab.FindField(fldName) val = polyFTab.ReturnValue(infld,s) dataVTab.SetValue(fld,newrec,val) end end end av.SetStatus(100*(recnum+1)/numRecs) 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