' Written by Timothy S. Thomas. ' Programming began 4/9/04. ' Last update was 4/9/04. ' *********************************************************************** ' Modifies my area calc no projection required.ave, to compute the length ' of polylines instead of areas of polygons ' It puts the computed lengths into a dbf file, and joins them to the original ' shapefile. ' *********************************************************************** ' Beginning program theProject = av.GetProject theView = av.GetActiveDoc theTheme = theView.GetActiveThemes.Get(0) theFTab = theTheme.GetFTab ' ********************************************************** ' Establish unique polygon id ' ********************************************************** ' This allows the user to pick a field as the basic unit for ' evaluation. fieldList = theFTab.GetFields.Clone fieldList.Insert("") idString = MsgBox.ChoiceAsString(fieldList,"Select ID field", "Choose ID field") if (idString = "") then theFTab.SetEditable(True) isFld = theFTab.FindField("UniqID") if (isFld <> nil) then idnew = MsgBox.YesNo("UniqID is already a field. Do you want to use it?", "Use UniqID?",True) if (idnew) then idField = isFld else newName = MsgBox.Input("Name of new ID","New name","NewID") idField = Field.Make(newName,#FIELD_LONG,8,0) theFTab.AddFields({idField}) for each rec in theFTab theFTab.SetValue(idField,rec,rec+1) end end else idField = Field.Make("UniqID",#FIELD_LONG,8,0) theFTab.AddFields({idField}) for each rec in theFTab theFTab.SetValue(idField,rec,rec+1) end end theFTab.SetEditable(False) else idField = idString end idString = idField.AsString ' A nice way to get a directory name and use it FTabFN = theFTab.GetSrcName.GetFileName baseString = FTabFN.GetBaseName extString = FTabFN.GetExtension newString = FTabFN.AsString.Substitute(baseString,"") new2String = baseString.Substitute(extString,"dbf") theFN = FileDialog.Put( (newString + "Length of " + new2String).AsFileName, "*.dbf","Data file name") dataVTab = VTab.MakeNew(theFN,dBase) newLenString = MsgBox.Input("8 characters or less, no spaces", "Variable name for length field","NewLen") newidField = idField.Clone newLenField = Field.Make(newLenString,#Field_Double,16,2) dataVTab.AddFields({newidField,newLenField}) dataVTab.SetEditable(True) theFTab.SetEditable(True) shapeField = theFTab.FindField("Shape") numRecs = theFTab.GetNumRecords ' Shows message in message bar av.ShowMsg("Calculating length") for each r in theFTab thePolyline = theFTab.ReturnValue(shapeField,r) outrec = dataVTab.AddRecord dataVTab.SetValue(newidField,outrec,theFTab.ReturnValue(idField,r)) dataVTab.SetValue(newLenField,outrec,thePolyline.ReturnLength) av.SetStatus(100*(r+1)/numRecs) end ' Clears message in message bar av.ClearMsg removeList = List.Make for each d in theProject.GetDocs if (d.AsString = newLenString 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(newLenString) theFTable = theTheme.EditTable ' Join DBF file to FTab theFTab.Join(idField, dataVTab, newidField) ' Turns off editing theFTab.SetEditable(false) dataVTab.SetEditable(false) dataTableWin.Close av.PurgeObjects