Back to Avenue Source Code Home

'---------------------------------
'Name: gridupdtar.Bat
'Date: 1-21-01
'Author: Marco Morais
'
' prompts the user for grids on disk
'
' exports the VAT from each grid to a .DBF file
' on disk with the following information:
' (1) numeric field named 'Value' (default)
' (2) numeric field named 'Count' (default)
' (3) numeric field named 'area_m2'
'     area (meters^2) in grid occupied by each value
' (4) numeric field named 'area_ha'
'     area (hectares) in grid occupied by each value
'
' WARNING: assumes all grid units are meters
'
'Returns:
'NILL
'
'Called By:
'MANY
'
'Calls:
'None
'
'Arguments:
'None
'---------------------------------

MsgBox.Report("Grid.AddGridsAvl" + NL +
              "1. prompts the user for grids on disk" + NL +
              "2. exports the VAT from each grid to a .DBF file" + NL +
              "   on disk with the following information:" + NL +
              "   (a) numeric field named 'Value' (default)" + NL +
              "   (b) numeric field named 'Count' (default)" + NL +
              "   (c) numeric field named 'area_m2'" + NL +
              "   (d) numeric field named 'area_ha'" + NL +
              "WARNING: assumes all grid units are meters", "About Script....")

'---------------------------------------
'retrieve list of grids to load
'---------------------------------------
theGridsSrcNameList = SourceDialog.ShowClass("Select the Grid(s) whose VAT will be exported", Grid)
if ( theGridsSrcNameList.Count = 0 )  then
  return NIL
end

'---------------------------------------
'make grids from srcnames 
'---------------------------------------
theGridsList = List.Make
for each srcn in theGridsSrcNameList
  theGrid = Grid.Make(srcn)
  if ( theGrid.HasError ) then
    MsgBox.Error("Grid not created:" ++ srcn.GetName, "Error")
    continue
  end
  theGridsList.Add(theGrid)
end

'---------------------------------------
'export each VAT
'---------------------------------------
for each g in theGridsList
  theGridVtab = g.GetVtab
  if ( theGridVtab = NIL ) then
    continue
  end  
  theExpGridVtab = theGridVtab.Export(((g.GetSrcName.GetFileName.GetName).AsFileName), dBASE, FALSE)
  theExpGridVtab.SetEditable(TRUE) 
  theGridCellSize = g.GetCellSize
  theGridArea = theGridCellSize * theGridCellSize
  the_area_m2_Field = Field.Make("area_m2", #FIELD_DOUBLE, 16, 0)
  the_area_ha_Field = Field.Make("area_ha", #FIELD_DOUBLE, 16, 0)
  theExpGridVtab.AddFields({the_area_m2_Field, the_area_ha_Field})
  theExpGridVtab.Calculate("[Count] * " + theGridArea.AsString, the_area_m2_Field)
  theExpGridVtab.Calculate("[Count] * (" + theGridArea.AsString + " * 0.0001 )", the_area_ha_Field)
  theExpGridVtab.Flush
  theExpGridVtab.SetEditable(FALSE)
end

av.PurgeObjects

return NIL



Last Updated: Marco Morais