/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* /* Codeloop.aml /* Date: 3/25/2002 /* Author: B.L. Brock /* Div. of Biology, Kansas State University /* /* Description: /* This program finds loops in National Hydrology Database (NHD) covers and flags /* selected arcs for ommission when calculating stream orders. The program finds loops, /* adds them to a selected set, and then steps through each loop prompting the user to /* select the arc(s) for recoding. All operations are done on a copy of the original /* cover named /* _E. A new item is created in the _E.aat name CTYPE. Arcs with CTYPE = 2 /* are coded from ommission from stream order calculations. CTYPE = 1 is the default. /* /* Requirements: This program uses a slightly modified version of sfd.aml written by /* J. Johnston available in the ESRI Arcscripts library. sfd.aml must be present in the /* ATOOL directory. Note: if you obtain sfd.aml from the arcscripts library, you mus make /* the following change: /* Change line 32 (counting blank lines) of routine N from: /* &s .sf$currec = 1 /* To: /* &s .sf$currec = 0 /* /* WARNING!!! This program removes pseudonodes from all arcs in the cover. Be sure to /* check for, and repair all eyeball loops in the cover using loopfix.aml before running /* this program. /* /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% &args cover image &severity &error &ignore /* Check whether an edit cover is open and close it if necessary. &sv ec [entryname [show ec]] &if ^ [null %ec%] &then &do &sv save = [response 'Save changes to %ec% ? (y/n)' n] &if %save% = 'y' &then save yes removeedit all yes &end /* Check for existence of _E and create it if it does not exist. If it does exist, /* prompt user whether they want to make changes to the existing cover. &if [exists %cover%_E -cover] &then &do &type &type &type &type %cover%_E already exists. Select action to take: &type 1 - Edit existing cover. &type 2 - Reset existing cover and recode. &type 3 - Delete existing cover and create new one. &type 4 - Quit &sv choice = [response 'Choose action...' 1] &select %choice% &when 1 &do &type Setting edit cover to %cover%_E... &sv cover = %cover%_E &end &when 2 &do &type Resetting all arcs to CTYPE = 1... &sv cover = %cover%_E ec %cover% ef arc sel all calc CTYPE = 1 &end &when 3 &do apc arc kill %cover%_E all apc arc copy %cover% %cover%_E &sv cover = %cover%_E &end &when 4 &do &type Quitting codeloop.aml... &return &end &end &end &else &do &type copying %cover% to %cover%_E... apc arc copy %cover% %cover%_E &sv cover = %cover%_E &end ec %cover% &messages &off &all /* Add background image if specified in arguments &if ^ [null %image%] &then &do image %image% image on &end /* check for existence of CTYPE and create if it does not exist &if [iteminfo %cover% -line ctype -exists] = .FALSE. &then &call makectype &if [exists arcfile -file] &then [delete arcfile -file] &type &type Please wait while Arc/Info prepares your hydrology cover for editing.... /* set editcoverage to proper cover for editing and set up draw environment for editing. ec %cover% drawe all off draw ef arc sel all unsplit none sel ctype = 1 &if [show number selected] > 0 &then calc ctype = 5 /* Build the cover to be edited in arc. Note: build must be /* run under arc prompt to preserve unique internal record numbers. save yes removeedit all yes apc arc build %cover% poly apc arc createlabels %cover% ec %cover% symbolitem arc ctype symbolitem poly 6 drawe all off ef poly /* loops through each polygon for editing sel all sfd n &sv num = [show number selected] &sv count = 1 &do &until %count% gt %num% ef poly sfd f &mess &off &all drawe poly off drawe arc node draw ef arc &type You are editing polygon %count% of %num%. &type Select the arc(s) to recode. Hit "9" when finished... sel many draws &call addarcs &s count = %count% + 1 &end ef arc &call getarcs calc ctype = 2 sel ctype = 5 calc ctype = 1 &mess &on sfd q drawe node off draw save yes &call report &return /*------------------------------------------------------------------------------------ /*------------------------------------------------------------------------------------ /* This routine adds the internal numbers of selected arcs to a file for /* subsequent generation of a selected set and batch processing. &routine addarcs cursor open &s arcfileunit = [open ARCFILE openstat -a] &do &while %:edit.AML$NEXT% &if [write %arcfileunit% [value :edit.[entryname [show ec]]#]] = 0 &then &type ARCFILE written successfully cursor next &end cursor close &if [close %arcfileunit%] = 0 &then &type ARCFILE closed successfully &return /*------------------------------------------------------------------------------------ /*------------------------------------------------------------------------------------ /* This routine creates a new selected set of all previously selected arcs written to /* ARCFILE by the addarc routine. &routine getarcs unsel all &s fileunit := [open ARCFILE openstat -r] &if %openstat% ne 0 &then &return &error Error opening file. /* Read from the file. &s record := [read %fileunit% readstat] /*When the end of the file is reached, READSTAT is set to 102 by [READ], /* and the loop terminates: &do &while %readstat% ne 102 asel [entryname[show ec]#] = %record% &s record := [read %fileunit% readstat] &type %readstat% &end /* Close the file unit. &s closestat := [close %fileunit%] &return /*--------------------------------------------------------------------- /*--------------------------------------------------------------------- /* This routine reports the number of loops detected and the number of arcs coded &routine report &mess &off &all ef poly sel all &s polynum = [show number selected] ef arc sel ctype = 2 &s arcnum = [show number selected] &mess &on &type &type Codeloop.aml has completed successfully. &type Detected stream loops ....................... %polynum% &type Number of arcs coded ....................... %arcnum% &return /* ---------------------------------------------------------------------- /* ---------------------------------------------------------------------- /* This routine creates item CTYPE in .aat. &routine makectype /* ec %cover% ef arc /* &if [iteminfo %cover% -line ctype -exists] = .FALSE. &then additem CTYPE 4 2 i sel all calc ctype = 1 &return /* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------