English

How To: Reclassify grid themes using Avenue

Summary

Note:
The information in this article applies to ArcView GIS versions 3.x only. The instructions described apply to the Avenue programming language, which is specific to the ArcView GIS application.

The Spatial Analyst extension allows you to change grid cells values using the Reclassify Values dialog box. There may be instances when your application requires you accomplish this task using Avenue. The examples in this article show you how to do this by applying the Reclass, ReclassByClassList, SetNull, or Con requests to the grid Avenue class.

Procedure

You may modify these examples to suit your needs.

  • Reclassify one value or range of values to another using the Reclass request. For example, change cell values between 50 and 100 to 150.
theView = av.getactivedoc 
theTheme = theView.Getactivethemes.Get(0) 
inGrid = theTheme.GetGrid 

'-- Get input and output values from the user 
chgList = MsgBox.MultiInput 
("Enter range values", 
"Reclassify cells", 
{"Input "+"from".quote+" cell value", "Input "+"to".quote+" cell value","Change to this output cell value"}, 
{"","",""}) 

If (chgList.count = 0) then
  exit
End

chgFrom1 = chgList.Get(0)
chgFrom2 = chgList.Get(1) 
chgTo = chgList.Get(2) 

if (chgFrom1.IsNumber and chgTo.IsNumber) then 
 
  '-- Make a new VTab to hold the to and from reclass values 
  outname = av.GetProject.GetWorkDir.MakeTmp("rec", "dbf") 
  recVtab = VTab.MakeNew(outname,dBASE) 
  frmField = Field.Make("frmFld",#field_short,10,0) 
  toField = Field.Make("toFld",#field_short,10,0) 
  outField = Field.Make("outFld",#field_short,10,0) 
  recVtab.AddFields({frmField,toField,outField}) 
  recnum = recVtab.AddRecord 

'-- Populate the VTab with the to and from reclass values 
  recVtab.SetValue(frmField,recnum,chgFrom1.AsNumber) 
  recVtab.SetValue(toField, recnum,chgFrom2.AsNumber) 
  recVtab.SetValue(outField,recnum,chgTo.AsNumber) 

  While (TRUE)
    again = MsgBox.YesNo("Would you like to add another value?","Reclass",TRUE)
    if (not again) then
      break
    else
      chgList = MsgBox.MultiInput ("Enter range values", "Reclassify cells", 
      {"Input "+"from".quote+" cell value", "Input "+"to".quote+" cell value","Change to this output cell value"}, 
      {"","",""}) 

      chgFrom1 = chgList.Get(0)
      chgFrom2 = chgList.Get(1) 
      chgTo = chgList.Get(2)
 
      recnum = recVtab.AddRecord 
 
      '-- Populate the VTab with the to and from reclass values 
      recVtab.SetValue(frmField,recnum,chgFrom1.AsNumber) 
      recVtab.SetValue(toField, recnum,chgFrom2.AsNumber) 
      recVtab.SetValue(outField,recnum,chgTo.AsNumber)
    end
  end

  '-- Reclassify the input Grid. Make a new output Grid 
  r = inGrid.Reclass(recVtab,frmField,toField,outField,false) 
 
  '-- Set name of data set 
  reclassFN = av.GetProject.GetWorkDir.MakeTmp("rctemp", "") 
  r.Rename(reclassFN) 
 
  '-- Check if output is OK
  if (r.HasError) then 
    msgbox.info("r.HasError","") 
    return NIL end 

  '-- Create a theme (after renaming data set) 
  gthm = GTheme.Make(r) 
 
  '-- Set name for theme 
  gthm.SetName("Reclass of " + theTheme.GetName) 
  '-- Add theme to the View 
  theView.AddTheme(gthm) 

  recVTab.DeActivate
  File.Delete(outname)
end
  • Reclassify one value to another using the Con request. For example, change cell values of 187 to 253.
theView = av.getactivedoc 
theTheme = theView.Getactivethemes.Get(0) 
inGrid = theTheme.GetGrid 

'-- Get input and output values from the user 
chgList = MsgBox.MultiInput 
("Enter value to change", 
"Reclassify cells", 
{"Input "+"from".quote+" cell value","Change to this output cell value"}, 
{"",""}) 

If (chgList.Count = 0) then
  exit
End
 
chgFrom = chgList.Get(0)
chgTo = chgList.Get(1) 

if (chgFrom.IsNumber and chgTo.IsNumber) 
then 
  r = (inGrid = chgFrom.AsNumber).Con(chgTo.AsNumber.AsGrid,inGrid) 
  gthm = GTheme.Make(r)
  if (r.HasError) then 
    msgbox.info("Output Grid has an error","") 
    return NIL end 
  gthm.SetName("Reclass of " + theTheme.GetName) 
  theView.AddTheme(gthm) 
end
  • Reclassify from a real value to NODATA, using the SetNull request. For example, change cell values of 98 to NODATA.
theView = av.getactivedoc 
theTheme = theView.Getactivethemes.Get(0) 
inGrid = theTheme.GetGrid 

'-- Get input and output values from the user 
chgFrom = MsgBox.Input("Enter cell number value", "Reclassify cells to NO DATA","") 

If (chgFrom = nil) then
  exit
End

if (chgFrom.IsNumber) 
then 
  r = (inGrid = chgFrom.AsNumber.AsGrid).SetNull(inGrid) 
  gthm = GTheme.Make(r) 
'-- Check if output is ok 
  if (r.HasError) then 
    msgbox.info("Output Grid has an error","") 
    return NIL end 
  gthm.SetName("Reclass of " + theTheme.GetName) 
  theView.AddTheme(gthm) 
end 
  • Reclassify from NODATA to a real value, using the Con request. For example, change NODATA cell to a cell values of 678.
Code:
theView = av.getactivedoc 
theTheme = theView.Getactivethemes.Get(0) 
inGrid = theTheme.GetGrid 

'-- Get input and output values from the user 
chgTo = MsgBox.Input("Enter cell number value", "Reclassify NO DATA cells to a number","")

If (chgTo = nil) then
  exit
End
 
if (chgTo.IsNumber) 
then 
  r= (inGrid.IsNull).Con(chgTo.AsNumber.AsGrid,inGrid) 
  gthm = GTheme.Make(r) 
  if (r.HasError) then 
    msgbox.info("Output Grid has an error","") 
    return NIL end 
  gthm.SetName("Reclass of " + theTheme.GetName) 
  theView.AddTheme(gthm) 
end