' Grid as Polygons.ave ' Written by Timothy S. Thomas ' Began programming 8/30/00 ' Last modified 8/30/00 ' This program makes a poly theme of squares, representing the outline of ' gridcells. ' For a very large grid, the program crashed (at cell 8845) when I tried ' to write values, but ran fine when I elected not to write values. The ' crash gave an error message indicating that there was a problem in one ' of Arc View's C files. theProject = av.GetProject theView = av.GetActiveDoc theThemeList = theView.GetActiveThemes theTheme = theThemeList.Get(0) theGrid = theTheme.GetGrid ' Set output precision Script.The.SetNumberFormat( "d.ddddd" ) theShapeFN = FileDialog.Put( ("c:\temp\temp.shp").AsFileName, "*.shp","New polygon shapefile filename") ' Create the FTab for the new shape file... newFTab = FTab.MakeNew(theShapeFN, Polygon) answerString = MsgBox.Input("Do you want to extract the value of the grid?", "Grid Value?","Yes") ' Name fields for output shapefile newshapeFld = newFTab.FindField("Shape") rowField = Field.Make("Row",#FIELD_LONG,8,0) colField = Field.Make("Col",#FIELD_LONG,8,0) valueField = Field.Make("Value",#FIELD_DOUBLE,16,4) if (answerString = "Yes") then newFTab.AddFields({rowField,colField,valueField}) theProjection = Prj.MakeNull else newFTab.AddFields({rowField,colField}) end extentRect = theGrid.GetExtent ulx = extentRect.GetLeft uly = extentRect.GetTop cellsize = theGrid.GetCellSize rowscols = theGrid.GetNumRowsAndCols nrows = rowscols.Get(0) ncols = rowscols.Get(1) recCnt = 0 numRecs = nrows*ncols if (answerString = "Yes") then for each r in 1..nrows for each c in 1..ncols rectllx = ulx+((c-1)*cellsize) rectlly = uly-(r*cellsize) recturx = ulx+(c*cellsize) rectury = uly-((r-1)*cellsize) theRectangle = Rect.MakeXY(rectllx,rectlly,recturx,rectury) theRecord = newFTab.AddRecord newFTab.SetValue(newshapeFld, theRecord, theRectangle.AsPolygon) newFTab.SetValue(rowField, theRecord, r) newFTab.SetValue(colField, theRecord, c) centerx = rectllx + (cellsize/2) centery = rectlly + (cellsize/2) centerPoint = Point.Make(centerx,centery) theValue = theGrid.CellValue(centerPoint,theProjection) newFTab.SetValue(valueField, theRecord, theValue) recCnt = recCnt + 1 av.SetStatus(100*recCnt/numRecs) end end else for each r in 1..nrows for each c in 1..ncols rectllx = ulx+((c-1)*cellsize) rectlly = uly-(r*cellsize) recturx = ulx+(c*cellsize) rectury = uly-((r-1)*cellsize) theRectangle = Rect.MakeXY(rectllx,rectlly,recturx,rectury) theRecord = newFTab.AddRecord newFTab.SetValue(newshapeFld, theRecord, theRectangle.AsPolygon) newFTab.SetValue(rowField, theRecord, r) newFTab.SetValue(colField, theRecord, c) recCnt = recCnt + 1 av.SetStatus(100*recCnt/numRecs) end end 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)