' '---------------------------- '--- Creation information --- '---------------------------- ' 'Name: pickgrid.ave 'Version: 1.0 '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 --- '--------------------------- ' 'This program picks up the value from a grid at the centroid of the polygon and 'writes it to the specified field in the polygon attribute table. ' '---------------- '--- Get view --- '---------------- ' theview = av.getactivedoc vgraphics = theview.getgraphics ' '------------------ '--- Get themes --- '------------------ ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "BALANCE") exit end if (theactivethemes.count = 1) then msgbox.error("Only one active theme found", "BALANCE") exit end if (theactivethemes.count > 2) then msgbox.error("Too many active themes found", "BALANCE") exit end if (theactivethemes.count = 2) then gfound = false pfound = false for each activetheme in theactivethemes if (activetheme.getclass.getclassname = "gtheme") then thegtheme = activetheme gfound = true end if (activetheme.getclass.getclassname = "ftheme") then theptheme = activetheme pfound = true end end end if (not gfound) then msgbox.error("One theme needs to be a grid theme", "BALANCE") exit end if (not pfound) then msgbox.error("One theme needs to be a polygon theme", "BALANCE") exit end ' '--------------------- '--- Set up themes --- '--------------------- ' 'grid theme ' thegrid = thegtheme.getgrid ' 'check below causes error crash for some reason ' 'if (thegrid = nil) then ' msgbox.error("Can't open grid theme","BALANCE") ' exit 'end thecellsize = thegrid.getcellsize ' 'polygon theme ' pftab = theptheme.getftab if (pftab = nil) then msgbox.error("Can't open polygon theme","BALANCE") exit end ' pshapef = pftab.findfield("shape") if (pshapef = nil) then msgbox.error("Can't find 'shape' field in polygon theme","BALANCE") exit end ' pfields = pftab.getfields pvaluef = msgbox.listasstring(pfields, "Field to write to:", "BALANCE") if (pvaluef = nil) then exit end ' '----------------- '--- Calculate --- '----------------- ' '--- Initial set up --- ' 'make polygon attribute table editable ' pftab.seteditable(true) ' '--- Loop --- ' for each prec in pftab ' 'get centroid ' pshape = pftab.returnvalue(pshapef, prec) cenp = pshape.returncenter ' 'plot centroid ' cengs = graphicshape.make(cenp) vgraphics.add(cengs) ' 'check if centroid is in polygon ' inside = cenp.iscontainedin(pshape) if (not inside) then msgbox.error("Polygon centroid not inside polygon", "BALANCE") end ' 'get value ' val = thegtheme.returncellvalue(cenp) ' 'write value to polygon attribute table ' pftab.setvalue(pvaluef, prec, val) ' end ' 'make polygon attribute table non editable ' pftab.seteditable(false) ' 'final message to user ' message = "Grid value picked" msgbox.info(message,"BALANCE") ' '----------- '--- End --- '----------- '