' '---------------------------- '--- Creation information --- '---------------------------- ' 'Name: calcarea.ave 'Version: 1.0 'Date: 02/16/97 'Author: Ferdi Hellweger ' Center for Research in Water Resources ' The University of Texas at Austin ' ferdi@crwr.utexas.edu ' '--------------------------- '--- Purpose/Description --- '--------------------------- ' 'This program computes the area. ' '--------------------------------------------- '--- Check if units configuration happened --- '--------------------------------------------- ' if (not _configu) then configure = msgbox.yesno("Units are not configured. Configure it now?","BALANCE",true) if (configure) then av.run("balconu", nil) else exit end end ' '---------------- '--- Get view --- '---------------- ' theview = av.getactivedoc ' '----------------- '--- Get theme --- '----------------- ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "BALANCE") exit end if (theactivethemes.count > 1) then msgbox.error("Too many active themes found", "BALANCE") exit end theptheme = theactivethemes.get(0) pftab = theptheme.getftab pshapef = pftab.findfield("shape") pshape = pftab.returnvalue(pshapef,0) if (not (pshape.getclass.getclassname = "polygon")) then msgbox.error("The theme needs to be a polygon theme", "BALANCE") exit end ' '-------------------- '--- Set up theme --- '-------------------- ' af = pftab.findfield("a") if (af = nil) then addfield = msgbox.yesno("Can't find 'a' field in polygon theme. Add it?","BALANCE", true) if (addfield) then pftab.seteditable(true) af = field.make("a", #FIELD_DECIMAL, 16, 4) pftab.addfields({af}) pftab.seteditable(false) else exit end end ' ' '----------------- '--- Calculate --- '----------------- ' '--- Initial set up --- ' 'make polygon attribute table editable ' pftab.seteditable(true) ' '--- Loop --- ' for each prec in pftab ' 'calculate area ' pshape = pftab.returnvalue(pshapef, prec) lshape = pshape.aspolyline mpoint = lshape.asmultipoint plist = mpoint.aslist n = plist.count i = 1 a = 0 for each prec in plist yterm = plist.get(i - 1).gety if (i < n ) then xterma = plist.get(i).getx end if (i = n ) then xterma = plist.get(0).getx end if (i > 1) then xtermb = plist.get(i - 2).getx end if (i = 1) then xtermb = plist.get(n - 1).getx end a = a + (yterm * (xterma - xtermb)) i = i + 1 end a = 0.5 * a.abs ' 'write a to polygon attribute table ' pftab.setvalue(af, prec, a) ' end ' 'make polygon attribute table non editable ' pftab.seteditable(false) ' 'final message to user ' message = "Area, a calculated" msgbox.info(message,"BALANCE") ' '----------- '--- End --- '----------- '