/*-------------------------------Name---------------------------------------- /* interactsheds.aml /*----------------------------- Purpose ------------------------------------- /* This ARC MACRO LANGUAGE program delineates watersheds based on user input /* of either a point outlet or a polygonal outlet area. Since all values /* in cell processing are tied to a cell, which is always an area, the "point" /* represents a single cell outlet, while a "polygon" represents an area /* of any shape or a multi-cell outlet. Furthermore the program SNAPPOUR /* moves the point outlets to fall on a drainage that is within the user /* specified distance in map units from the user defined outlet. Since it /* can be difficult to interactively place the outlet so that it falls on a /* drainage, SNAPPOUR adjusts the location of the outlet. If the user /* specifies "0" for the snap distance SNAPPOUR will not change the location /* of the outlet. /* /*----------------------------- History ------------------------------------- /* /* Jacek Blaszczynski Physical Scientist BLM NARSC /* 08/99 Original Coding /* /*=========================================================================== &severity &error &routine bailout &args input_elev output_shed type snap_dist /* Check arguments &call chkargs /* Setup &amlpath and &menupath for ARCTOOLS &call setpaths /* Do the work &call main &call exit &return /* End of interactsheds.aml /*-------------- &routine chkargs /*-------------- &if [SHOW PROGRAM] <> GRID &then &do &type This aml must be run from GRID. &call bailout &end &do arg &list input_elev output_shed type &if [NULL [VALUE %arg%]] &then &do &call usage &call bailout &end &end &if not [EXISTS %input_elev% -GRID] &then &do &type Input grid: %input_elev%, does not exist. &call bailout &end &if [EXISTS %output_shed% -GRID] &then &do &type Output grid %output_shed% already exists. &call bailout &end &if [LENGTH %output_shed%] > 13 &then &do &type Grid names must be 13 characters or less. &call bailout &end &s type = [UPCASE %type%] &s valid_types = {'POINT','POLY'} &if not [QUOTE %type%] in %valid_types% &then &do &type Invalid keyword for argument 3. &call usage &call bailout &end &select %type% &when POLY; &do &if not [NULL %snap_dist%] &then &do &type Snap distance not required when using POLY option. &call bailout &end &end &when POINT; &do &if [NULL %snap_dist%] &then &do &type Snap distance is required when using the POINT option &call bailout &end &else &do &s datatype = [TYPE %snap_dist%] &if %datatype% <> -1 &then &do /* Not integer &type Snap distance must be a positive integer. &call bailout &end &else &do &if %snap_dist% < 1 &then &do &type Snap distance must be a positive integer. &call bailout &end &end &end &end &end &return /* End of routine chkargs /*----------- &routine main /*----------- &terminal 9999 display 9999 2 position cr gridnodatasymbol transparent MAPEXTENT %input_elev% GRIDPAINT %input_elev% VALUE LINEAR WRAP GRAY /*--------------------------------------------- /* Calculate watershed for polygonal input /*--------------------------------------------- &select %type% &when POLY; &do &call buildgrds &call getpoly seed2 = int (seed / seed ) seed3 = regiongroup (seed2) %output_shed% = watershed (flowdirz, seed3) &end /*--------------------------------------------- /* Calculate watershed for point input /*--------------------------------------------- &when POINT; &do &call buildgrds &call getpoint seed2 = int (seed) seed3 = regiongroup (seed2) seed4 = snappour (seed, flowcountz, %snap_dist%) %output_shed% = watershed (flowdirz, seed4) &end &end gridshades %output_shed% &return /* End of routine main /*---------------- &routine buildgrds /*---------------- &do grd &list seed seed2 seed3 seed4 &if [EXISTS %grd% -GRID] &then &do KILL %grd% &end &end &if not [EXISTS filled -GRID] &then &do fill %input_elev% filled &end &if not [EXISTS flowdirz -GRID] &then &do flowdirz = flowdirection (filled) &end &if not [EXISTS flowcountz -GRID] &then &do flowcountz = flowaccumulation (flowdirz) &end &return /* End of routine buildgrds /*-------------- &routine getpoly /*-------------- &s mess1 = 'Define a watershed outlet area, use 9 to quit.' &r msinform init %mess1% seed = SELECTPOLYGON(%input_elev%, *, INSIDE) &return /* End of routine getpoly /*--------------- &routine getpoint /*--------------- &s mess1 = 'Define a watershed outlet point, use 9 to quit.' &r msinform init %mess1% seed = SELECTPOINT(%input_elev%, *, INSIDE) &return /* End of routine getpoint /*--------------- &routine setpaths /*--------------- &s amlpath = [SHOW &amlpath] &s menupath = [SHOW &menupath] &if not [NULL %amlpath%] &then &do &s old$amlpath = %amlpath% &amlpath $ATHOME/lib &end &else &do &s old$amlpath = [SHOW &workspace] &amlpath $ATHOME/lib &end &if not [NULL %menupath%] &then &do &s old$menupath = %menupath% &menupath $ATHOME/lib,$ATHOME/icons &end &else &do &s old$menupath = [SHOW &workspace] &menupath $ATHOME/lib,$ATHOME/icons &end &return /* End of routine setpaths /*------------ &routine usage /*------------ &type Usage: &r interactsheds > &return /* End of routine usage /*----------- &routine exit /*----------- &if [VARIABLE old$amlpath] &then &do &amlpath %old$amlpath% &end &if [VARIABLE old$menupath] &then &do &menupath %old$menupath% &end &return /* End of routine exit /*-------------- &routine bailout /*-------------- &severity &error &ignore &call exit &return &error Bailing out of interactsheds.aml...