' '---------------------------- '--- Creation information --- '---------------------------- ' 'Name: connect.ave 'Version: 1.0 'Date: 02/13/97 'Author: Ferdi Hellweger ' Center for Research in Water Resources ' The University of Texas at Austin ' ferdi@crwr.utexas.edu ' '--------------------------- '--- Purpose/Description --- '--------------------------- ' 'This program modifies an elevation grid based on a polygon grid. 'It digs sinks for the polygons so the flowaccumulation will accumulate 'at the polygon centroids. Use the pickload program to pick of loads. ' ' '---------------- '--- Get view --- '---------------- ' theview = av.getactivedoc vgraphics = theview.getgraphics ' '------------------ '--- Get themes --- '------------------ ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "CONNECT") exit end if (theactivethemes.count = 1) then msgbox.error("Only one active theme found", "CONNECT") exit end if (theactivethemes.count = 2) then msgbox.error("Only two active theme found", "CONNECT") exit end if (theactivethemes.count > 3) then msgbox.error("Too many active themes found", "CONNECT") exit end if (theactivethemes.count = 3) then oegfound = false pfound = 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 if (theshape.getclass.getclassname = "polygon") then theptheme = activetheme pfound = true end end end end if (not oegfound) then msgbox.error("One theme needs to be a grid theme", "CONNECT") exit end if (not pfound) then msgbox.error("One theme needs to be a polygon theme", "CONNECT") exit end if (not lfound) then msgbox.error("One theme needs to be a line theme", "CONNECT") exit end ' '----------------- '--- Get input --- '----------------- ' keeptemp = msgbox.yesno("Keep temporary data sets?", "CONNECT", false) ' '--------------------- '--- 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","CONNECT") ' exit 'end oegextend = oegrid.getextent oegcellsize = oegrid.getcellsize ' 'polygon theme ' pftab = theptheme.getftab if (pftab = nil) then msgbox.error("Can't open polygon theme","CONNECT") exit end ' pshapef = pftab.findfield("shape") if (pshapef = nil) then msgbox.error("Can't find 'shape' field in polygon theme","CONNECT") exit end ' 'line theme ' lftab = theltheme.getftab if (lftab = nil) then msgbox.error("Can't open line theme","CONNECT") exit end ' '----------------- '--- Calculate --- '----------------- ' '--- Initial set up --- ' 'setwindow grid.setanalysisextent(#GRID_ENVTYPE_VALUE, oegextend) ' 'setcell ' grid.setanalysiscellsize(#GRID_ENVTYPE_VALUE, oegcellsize) ' 'centroid grid ' cpfilename = av.getproject.makefilename("cenp", "shp") cpftab = ftab.makenew(cpfilename, point) cpshapef = cpftab.findfield("shape") cpfields = list.make cpgridvalf = field.make("gridval", #FIELD_DECIMAL, 16, 4) cpfields.add(cpgridvalf) cpftab.addfields(cpfields) cpftab.seteditable(true) for each prec in pftab pshape = pftab.returnvalue(pshapef, prec) cenp = pshape.returncenter cengs = graphicshape.make(cenp) vgraphics.add(cengs) inside = cenp.iscontainedin(pshape) if (not inside) then msgbox.error("Polygon centroid not inside polygon", "CONNECT") end theoutrec = cpftab.addrecord cpftab.setvalue(cpshapef, theoutrec, cenp) cpftab.setvalue(cpgridvalf, theoutrec, 1) end cpftab.seteditable(false) cengrid = grid.makefromftab(cpftab, prj.makenull, nil, nil) if (keeptemp) then cenfilename = av.getproject.makefilename("cengrid", "") cengrid.savedataset("/home1/alpha62/maidment/ex7/cengrid".asfilename) cengtheme = gtheme.make(cengrid) theview.addtheme(cengtheme) cengtheme.setvisible(true) end ' 'boundary grid ' bndgrid = grid.makefromftab(lftab, prj.makenull, nil, nil) if (keeptemp) then bndfilename = av.getproject.makefilename("bndgrid", "") bndgrid.savedataset("/home1/alpha62/maidment/ex7/bndgrid".asfilename) bndgtheme = gtheme.make(bndgrid) theview.addtheme(bndgtheme) bndgtheme.setvisible(true) end ' 'polygon grid ' polygrid = grid.makefromftab(pftab, prj.makenull, nil, nil) if (keeptemp) then polyfilename = av.getproject.makefilename("polygrid", "") polygrid.savedataset("/home1/alpha61/quenzeam/ex7/polygrid".asfilename) polygtheme = gtheme.make(polygrid) theview.addtheme(polygtheme) polygtheme.setvisible(true) end ' 'drop grid ' dropgrid = (polygrid.isnull).con(0.asgrid, (bndgrid.isnull).con(1.asgrid, 0.asgrid)) if (keeptemp) then dropfilename = av.getproject.makefilename("dropgrid", "") dropgrid.savedataset("/home1/alpha61/quenzeam/ex7/dropgrid".asfilename) dropgtheme = gtheme.make(dropgrid) theview.addtheme(dropgtheme) dropgtheme.setvisible(true) end ' 'cost grid ' costgrid = (dropgrid = 1.asgrid).con(1.asgrid, 1000000.asgrid) if (keeptemp) then costfilename = av.getproject.makefilename("costgrid", "") costgrid.savedataset("/home1/alpha61/quenzeam/ex7/costgrid".asfilename) costgtheme = gtheme.make(costgrid) theview.addtheme(costgtheme) costgtheme.setvisible(true) end ' 'dist grid ' distgrid = cengrid.costdistance(costgrid, nil, nil, nil) if (keeptemp) then distfilename = av.getproject.makefilename("distgrid", "") distgrid.savedataset("/home1/alpha61/quenzeam/ex7/distgrid".asfilename) distgtheme = gtheme.make(distgrid) theview.addtheme(distgtheme) distgtheme.setvisible(true) end ' 'modification parameters ' tmpgrid = (distgrid < 1000000.asgrid).con(distgrid, 0.asgrid) maxdist = tmpgrid.getstatistics.get(1) sinkelev = (-100 - (maxdist * 0.1)) ' 'modified elevation grid ' megrid = (dropgrid = 0.asgrid).con(oegrid, (sinkelev.asgrid + (0.1.asgrid * distgrid))) mefilename = av.getproject.makefilename("megrid", "") megrid.savedataset("/home1/alpha62/quenzeam/ex7/conngrid".asfilename) megtheme = gtheme.make(megrid) theview.addtheme(megtheme) megtheme.setvisible(true) ' 'final message to user ' message = "Grid connected" msgbox.info(message,"CONNECT") ' '----------- '--- End --- '----------- '