' '---------------------------- '--- Creation information --- '---------------------------- ' 'Name: agree.ave 'Version: 1.0.av 'Date: 03/01/97 'Author: Ferdi Hellweger ' Center for Research in Water Resources ' The University of Texas at Austin ' ferdi@crwr.utexas.edu ' '--------------------------- '--- Purpose/Description --- '--------------------------- ' 'AGREE is a surface reconditioning system for Digital Elevation Models (DEMs). 'The system adjusts the surface elevation of the DEM to be consistent with a 'vector coverage. The vecor coverage can be a stream or ridge line coverage. ' '---------------- '--- Get view --- '---------------- ' theview = av.getactivedoc ' '------------------ '--- Get themes --- '------------------ ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "AGREE") exit end if (theactivethemes.count = 1) then msgbox.error("Only one active theme found", "AGREE") exit end if (theactivethemes.count > 2) then msgbox.error("Too many active themes found", "AGREE") exit end if (theactivethemes.count = 2) then oegfound = false lfound = false for each activetheme in theactivethemes if (activetheme.getclass.getclassname = "gtheme") then oegtheme = activetheme oegfound = true end if (activetheme.getclass.getclassname = "ftheme") then theftab = activetheme.getftab theshapef = theftab.findfield("shape") theshape = theftab.returnvalue(theshapef,0) if (theshape.getclass.getclassname = "polyline") then theltheme = activetheme lfound = true end end end end if (not oegfound) then msgbox.error("One theme needs to be a grid theme", "AGREE") exit end if (not lfound) then msgbox.error("One theme needs to be a line theme", "AGREE") exit end ' '----------------- '--- Get input --- '----------------- ' labels = list.make labels = labels.add("Buffer distance") labels = labels.add("Smooth drop/raise distance (+ = up)") labels = labels.add("Sharp drop/raise distance (+ = up)") labels = labels.add("Keep temporary data sets?") ' defaults = list.make defaults = defaults.add("0") defaults = defaults.add("0") defaults = defaults.add("0") defaults = defaults.add("no") ' inputs = msgbox.multiinput("Enter run control parameters", "AGREE", labels, defaults) if (inputs.count = 0) then exit end ' buffer = inputs.get(0).asnumber smoothdist = inputs.get(1).asnumber sharpdist = inputs.get(2).asnumber if (inputs.get(3).ucase.left(1) = "Y") then keeptemp = true else keeptemp = false end ' '--------------------- '--- Set up themes --- '--------------------- ' 'grid theme ' oegrid = oegtheme.getgrid ' 'check below causes error crash for some reason ' 'if (thegrid = nil) then ' msgbox.error("Can't open grid theme","AGREE") ' exit 'end oegextend = oegrid.getextent oegcellsize = oegrid.getcellsize ' 'line theme ' lftab = theltheme.getftab if (lftab = nil) then msgbox.error("Can't open line theme","AGREE") exit end ' '----------------- '--- Calculate --- '----------------- ' '--- Initial set up --- ' 'setwindow ' grid.setanalysisextent(#GRID_ENVTYPE_VALUE, oegextend) ' 'setcell ' grid.setanalysiscellsize(#GRID_ENVTYPE_VALUE, oegcellsize) ' '--- AGREE method --- ' 'vectgrid ' vectgrid = grid.makefromftab(lftab, prj.makenull, nil, nil) if (keeptemp) then vectgridfilename = av.getproject.makefilename("vectgrid", "") vectgrid.savedataset(vectgridfilename) vectgridgtheme = gtheme.make(vectgrid) theview.addtheme(vectgridgtheme) vectgridgtheme.setvisible(true) end ' 'smogrid ' smogrid = (vectgrid.isnull).setnull(oegrid + smoothdist.asgrid).int if (keeptemp) then smogridfilename = av.getproject.makefilename("smogrid", "") smogrid.savedataset(smogridfilename) smogridgtheme = gtheme.make(smogrid) theview.addtheme(smogridgtheme) smogridgtheme.setvisible(true) end ' 'vectdist and vectallo ' vectallofilename = av.getproject.makefilename("vectallo", "") vectdist = smogrid.eucdistance(nil, vectallofilename, nil) if (keeptemp) then vectdistfilename = av.getproject.makefilename("vectdist", "") vectdist.savedataset(vectdistfilename) vectdistgtheme = gtheme.make(vectdist) theview.addtheme(vectdistgtheme) vectdistgtheme.setvisible(true) vectallosrcname = grid.makesrcname(vectallofilename.asstring) vectallo = grid.make(vectallosrcname) vectallo.savedataset(vectallofilename) vectallogtheme = gtheme.make(vectallo) theview.addtheme(vectallogtheme) vectallogtheme.setvisible(true) end ' 'bufgrid1 and bufgrid2 ' bufgrid1 = (vectdist > (buffer - (oegcellsize / 2)).asgrid).con(1.asgrid, 0.asgrid) bufgrid2 = (not bufgrid1).setnull(oegrid).int if (keeptemp) then bufgrid1filename = av.getproject.makefilename("bufgrid1", "") bufgrid1.savedataset(bufgrid1filename) bufgrid1gtheme = gtheme.make(bufgrid1) theview.addtheme(bufgrid1gtheme) bufgrid1gtheme.setvisible(true) bufgrid2filename = av.getproject.makefilename("bufgrid2", "") bufgrid2.savedataset(bufgrid2filename) bufgrid2gtheme = gtheme.make(bufgrid2) theview.addtheme(bufgrid2gtheme) bufgrid2gtheme.setvisible(true) end ' 'bufdist and bufallo ' bufallofilename = av.getproject.makefilename("bufallo", "") bufdist = bufgrid2.eucdistance(nil, bufallofilename, nil) if (keeptemp) then bufdistfilename = av.getproject.makefilename("bufdist", "") bufdist.savedataset(bufdistfilename) bufdistgtheme = gtheme.make(bufdist) theview.addtheme(bufdistgtheme) bufdistgtheme.setvisible(true) bufallosrcname = grid.makesrcname(bufallofilename.asstring) bufallo = grid.make(bufallosrcname) bufallo.savedataset(bufallofilename) bufallogtheme = gtheme.make(bufallo) theview.addtheme(bufallogtheme) bufallogtheme.setvisible(true) end ' 'smoelev ' smoelev = vectallo + (((bufallo - vectallo) / (bufdist + vectdist)) * vectdist) if (keeptemp) then smoelevfilename = av.getproject.makefilename("smoelev", "") smoelev.savedataset(smoelevfilename) smoelevgtheme = gtheme.make(smoelev) theview.addtheme(smoelevgtheme) smoelevgtheme.setvisible(true) end ' 'shagrid ' shagrid = (vectgrid.isnull).setnull(oegrid + sharpdist.asgrid).int if (keeptemp) then shagridfilename = av.getproject.makefilename("shagrid", "") shagrid.savedataset(shagridfilename) shagridgtheme = gtheme.make(shagrid) theview.addtheme(shagridgtheme) shagridgtheme.setvisible(true) end ' 'elevgrid ' elevgrid = (vectgrid.isnull).con(smoelev, shagrid) if (keeptemp) then elevgridfilename = av.getproject.makefilename("elevgrid", "") elevgrid.savedataset(elevgridfilename) elevgridgtheme = gtheme.make(elevgrid) theview.addtheme(elevgridgtheme) elevgridgtheme.setvisible(true) end ' 'final message to user ' message = "Grid agreed" msgbox.info(message,"AGREE") ' '----------- '--- End --- '----------- '