' Shape from Point and Area.ave ' Modifies Square from Point and Area.ave ' Written by Timothy S. Thomas ' Began programming 7/11/01 ' Last modified 7/11/01 ' This program takes a point (which locates the center of the data) and ' converts it into a shape having the area given by the specified variable. ' Need to run script to get x- and y-coordinates. ' This could be easily modified to convert other things, such as population, ' to proportional squares (or circles or rectangles, etc.). theProject = av.GetProject theView = av.GetActiveDoc theThemeList = theView.GetActiveThemes theTheme = theThemeList.Get(0) theFTab = theTheme.GetFTab ' Let changes be made to the FTab theFTab.SetEditable(True) ' Set output precision Script.The.SetNumberFormat( "d.ddddd" ) ' 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,"shp") theShapeFN = FileDialog.Put( (newString + "Poly " + new2String).AsFileName, "*.shp","New polygon shapefile filename") ' Create the FTab for the new shape file... newFTab = FTab.MakeNew(theShapeFN, Polygon) shapeList = { "Rectangle", "Circle" } shapeString = MsgBox.ListAsString(shapeList,"Choose output polygon type", "Poly Type") fieldList = theFTab.GetFields.Clone idField = MsgBox.ChoiceAsString(fieldList,"Select uniq id field", "ID Field") areaField = MsgBox.ChoiceAsString(fieldList,"Select area field", "Area Field") xField = MsgBox.ChoiceAsString(fieldList,"Select field with x value", "X Field") yField = MsgBox.ChoiceAsString(fieldList,"Select field with y value", "Y Field") convertareaMult = MsgBox.Input("Multiplier to convert area field to map units", "Area Conversion Multiplier","10000").AsNumber ' Clone fields to output shapefile newshapeFld = newFTab.FindField("Shape") newidFld = idField.Clone newareaFld = areaField.Clone newFTab.AddFields({newidFld,newareaFld}) numRecs = theFTab.GetNumRecords recCnt=0 for each r in theFTab x = theFTab.ReturnValue(xField,r) y = theFTab.ReturnValue(yField,r) if (shapeString = "Rectangle") then diam = ((convertareaMult*theFTab.ReturnValue(areaField,r)).Sqrt)/2 theShape = Rect.MakeXY(x-diam,y-diam,x+diam,y+diam) elseif (shapeString = "Circle") then thePoint = Point.Make(x,y) radiusNumber = ((convertareaMult*theFTab.ReturnValue(areaField,r)/3.14159).Sqrt) theShape = Circle.Make(thePoint,radiusNumber) else MsgBox.Info("Wrong shape","Wrong shape") Return nil end theRecord = newFTab.AddRecord newFTab.SetValue(newshapeFld, theRecord, theShape.AsPolygon) newFTab.SetValue(newidFld, theRecord, theFTab.ReturnValue(idField,r)) newFTab.SetValue(newareaFld, theRecord, theFTab.ReturnValue(areaField,r)) recCnt = recCnt + 1 av.SetStatus(100*recCnt/numRecs) end av.ClearMsg newFTab.Flush ' Create the new Theme NewThemeName = SrcName.Make(theShapeFN.AsString) NewTheme = Theme.Make(NewThemeName) ' Set the Theme name without the extension .shp NewTheme.SetName(theShapeFN.GetBaseName.AsTokens(".").Get(0)) ' Add it to the active View theView.AddTheme(NewTheme) ' Make sure the View is on top theView.GetWin.Activate ' Flag that the Project has been modified av.GetProject.SetModified(True) ' End of script View.AddGenerate