-
/*Channel module - Flo Damian
-
-
&terminal
9999 &keypad
-
&messages
&popup
-
&type
This program lets you compute a grid of stream segments selected by
-
&type
the folowing attributes: fine sediment deposit,
-
&type
discharge sensitive areas, wood loss and accumulation, catastrophic events.
-
&sv
attribute = [response 'select one attribute (fs, ds, wo, ce)']
-
&sv
streams = [response 'Name stream coverage']
-
&sv
dirtydem = [response 'Name current dem']
-
/*clean up sinks
-
&messages
&on
-
&type
'*********************************'
-
&type
'Filling dem. MAY take a long time'
-
fill
%dirtydem% dem sink
-
/*compute the downstream gradient and confinement
-
/*flow = flowdirection(dem, grad)
-
streamgrad
= con(%streams% and grad, grad)
-
smoothgrad
= %streams% * focalmean(streamgrad)
-
curv
= curvature(dem)
-
confine
= %streams% * curv
-
gradclass
= con(smoothgrad < 1, 1, smoothgrad < 2, 2, smoothgrad < 4, 3,
smoothgrad < 8, 4, smoothgrad < 20, 5, 6)
-
confclass
= con(confine < -2.5, 10, confine < -1.3, 20, 30)
-
streamclass
= gradclass + confclass
-
/*interactive query
-
&if
%attribute% = fs &then;
-
%attribute%
= con(streamclass == 11 or streamclass == 21 or streamclass == 12 or streamclass
== 22, 1,0);
-
&else
&if %attribute% = ds &then;
-
%attribute%
= con(streamclass == 12 or streamclass == 13 or streamclass == 22 or streamclass
== 23 or streamclass == 33, 1,0);
-
&else
&if %attribute% = wo &then;
-
%attribute%
= con(gradclass == 1, 2,gradclass >= 2 and gradclass <= 4, 1,0);
-
&else
&if %attribute% = ce &then;
-
%attribute%
= con(gradclass >= 3, 1,0);
-
end
-
display
9999
-
mape
%attribute%
-
image
%attribute%
-
&sv
cont = [response 'Do you want to continue? (y/n)']
-
&do
&while %cont% = y
-
&sv
attributte = [response 'select one attribute (fs, ds, wo, ce)']
-
&goto
top
-
&end
-
&messages
&on
-
kill
curv
-
kill
confine
-
kill
gradclass
-
kill
confineclass
-
&return
!you're done!
-
-
Avenue
Script for Channel Query
-
-
'Channel
Processes - Author Flo Damian
-
-
'
PART 1 creates a new att table and copies
-
'
values of a field to be joined later.
-
MsgBox.Info("Do
Not Select More Than One Theme ","")
-
'
Get a file name to create.
-
aFileName
= FileDialog.Put("channel.dbf".AsFileName,
-
"*.dbf","Create
Attribute Table")
-
if
(nil = aFileName) then
-
exit
-
end
-
'
Create a dBase table.
-
attVTab
= VTab.MakeNew (aFileName,dBase)
-
attVTab.SetEditable
(True)
-
idField
= Field.Make
-
("id",
#FIELD_CHAR, 4, 0)
-
fsField
= Field.Make
-
("FS",
#FIELD_CHAR, 4, 0)
-
csField
= Field.Make
-
("CS",
#FIELD_CHAR, 4, 0)
-
sdField
= Field.Make
-
("SD",
#FIELD_CHAR, 4, 0)
-
sfField
= Field.Make
-
("SF",
#FIELD_CHAR, 4, 0)
-
beField
= Field.Make
-
("BE",
#FIELD_CHAR, 4, 0)
-
wlField
= Field.Make
-
("WL",
#FIELD_CHAR, 4, 0)
-
waField
= Field.Make
-
("WA",
#FIELD_CHAR, 4, 0)
-
dfsField
= Field.Make
-
("DFS",
#FIELD_CHAR, 4, 0)
-
dfdField
= Field.Make
-
("DFD",
#FIELD_CHAR, 4, 0)
-
dbField
= Field.Make
-
("DB",
#FIELD_CHAR, 4, 0)
-
attVTab.AddFields
({idField, fsField, csField, sdField,
-
sfField,
beField, wlField, waField, dfsField, dfdField, dbField})
-
'
Get id values from the theme's table
-
'
and write to the new table.
-
thisView
= Av.GetActiveDoc
-
theList
= thisView.GetActiveThemes
-
_theTheme
=theList.Get(0)
-
_theVTab
= _theTheme.GetFTab
-
streamField
= _theVTab.FindField("id")
-
gridcodeField
= _theVTab.FindField("gridcode")
-
if
(nil = streamField) then
-
MsgBox.Error ("Unable to find the id field",
-
"")
-
exit
-
end
-
'
The record count is required for a loop.
-
recordCount
= _theVTab.GetNumRecords
-
if
(recordCount = 0) then
-
MsgBox.Error ("There are no records to copy",
-
"")
-
exit
-
end
-
'
Read and write each record.
-
for
each index in _theVTab
-
idValue =
-
_theVtab.ReturnValueString (streamField,index)
-
if (nil = idValue) then
-
continue
-
end
-
rec = attVTab.AddRecord
-
attVTab.SetValue (idField, rec,idValue)
-
-
c = _theVTab.ReturnValueString (gridcodeField, index)
-
if ((c= "11") or (c="12") or(c="21")or(c="22")) then
-
attVtab.SetValue (fsField, rec, "1")
-
end
-
if ((c="13")or(c="22")or(c="23")or(c="32")or(c="33")) then
-
attVTab.SetValue (csField, rec, "1")
-
end
-
if ((c="32")or(c="33")or(c="12")) then
-
attVTab.SetValue (sdField, rec, "1")
-
end
-
if ((c="13")or(c="23")or(c="24")or(c="34")) then
-
attVTab.SetValue (sfField, rec, "1")
-
end
-
if ((c="11")or(c="12")or(c="13")or(c="21")or(c="22")or(c="33")) then
-
attVTab.SetValue (beField, rec, "1")
-
end
-
if ((c="14")or(c="12")or(c="13")or(c="24")or(c="22")or(c="23")or(c="32")or(c="33")or(c="34"))
then
-
attVTab.SetValue (wlField, rec, "1")
-
end
-
if ((c="11")or(c="21")) then
-
attVTab.SetValue (waField, rec, "1")
-
end
-
if ((c="14")or(c="24")or(c="34")or(c="15")or(c="25")or(c="35")or(c="26")or(c="36"))
then
-
attVTab.SetValue (dfsField, rec, "1")
-
end
-
if ((c="13")or(c="23")or(c="33")or(c="14")or(c="24")or(c="34")) then
-
attVTab.SetValue (dfdField, rec, "1")
-
end
-
if ((c="13")or(c="14")or(c="23")or(c="24")or(c="33")or(c="34")) then
-
attVTab.SetValue (dbField, rec, "1")
-
end
-
end
-
attVTab.Flush
-
'
PART2 Join Att Table
-
'
Get the theme's table.
-
theJoinField
= _theVtab.FindField("id")
-
if
(nil = theJoinField) then
-
MsgBox.Error
-
("Theme's table does not have the join field",
-
"")
-
exit
-
end
-
'
Get the join table
-
forWrite
= false
-
skipFirst
= False
-
tableName
= aFileName.AsString
-
attTable
= FileName.FindInSystemSearchPath(tableName)
-
joinVTab
= VTab.Make(attTable, forWrite, skipFirst)
-
attJoinField
= joinVTab.FindField ("id")
-
if
(nil = attJoinField) then
-
MsgBox.Error
-
("Attribute table does not have the join field","")
-
exit
-
end
-
'
Join the tables.
-
_theVTab.Link
(theJoinField, joinVTab, attJoinField)
-
_theVTab.Join
(theJoinField, joinVTab, attJoinField)
-
'PART
3 Query attribute table and display the result
-
part3
= av.FindScript("flo2")
-
if
(nil = part3) then
-
MsgBox.Error("Unable to find Scriptx.ave","")
-
exit
-
else
-
av.Run("flo2","")
-
response = MsgBox.MiniYesNo("Do you want another query?",true)
-
while (true = response)
-
av.Run("flo2","")
-
end
-
end
-
-
-
'Script
2
-
-
theView
=av.GetActiveDoc
-
theBitMap
= _theVTab.GetSelection
-
aQStr
= QueryWin.ReturnQuery(_theVTab,"")
-
if
(nil = aQStr) then exit end
-
_theVtab.Query(aQStr,
theBitMap, #VTAB_SELTYPE_NEW)
-
theBitMap2
= _theVtab.GetSelection.count
-
if
(theBitMap2 > 0) then
-
afileName
= FileDialog.Put("attrib.shp".AsFileName,"*.shp",
-
"Give
a name for your theme file")
-
_theTheme.ExportToFTab(aFileName)
-
stringName
= aFileName.AsString
-
aSrcName
= SrcName.Make(stringName)
-
newTheme
= Theme.Make(aSrcName)
-
theView.AddTheme(newTheme)
-
else
MsgBox.Error("There are no streams to match your selection","")
-
end
-