/* STREAMLINESHED.AML /* Author: Jacek Blaszczynski 03/11/99 Original Coding /* /* /*------------------------------------------------------------------------------ /* /* This AML delineates watersheds for watershed outlets located at /* junctions and sources of a stream coverage. The program first creates basic /* hydrologic terrain analysis grid layers of a filled DEM ("filled"), /* flowdirection map for the filled DEM ("flowdirz" - the "z" suffix /* indicates the operation was performed on a filled DEM), and a /* flowaccumulation map ("flowcountz"). Then it uses a line vector stream /* map to identify the endpoints and points of intersection (nodes) of stream /* lines and make them into a point coverage. /* The point coverage is then rasterized to serve as outlets for watershed /* delineation. "SNAPPOUR" function is used to locate the streams /* in high flow accumulation areas (channels) modeled from the DEM /* within user specified distance in number of cells. Then the GRID "watershed" /* function calculates the watershed areas based on the outlets and the flow /* direction map. /* /*----------------------------------------------------------------------------- &severity &error &routine bailout &args source_dem in_streams out_sheds snap_dist /* Check arguments &call chkargs /* Do the work &call main &call exit &return /* End of streamlineshed.aml /*-------------- &routine chkargs /*-------------- &if [SHOW PROGRAM] <> GRID &then &do &type This aml must be run from GRID. &call bailout &end &do arg &list source_dem in_streams out_sheds snap_dist &if [NULL [VALUE %arg%]] &then &do &call usage &call bailout &end &end &if not [EXISTS %source_dem% -GRID] &then &do &type Input grid: %source_dem%, does not exist. &call bailout &end &if [LENGTH %source_dem%] > 13 &then &do &type Grid names must be 13 characters or less. &call bailout &end &if not [EXISTS %in_streams% -COVER] &then &do &type Input cover: %in_streams%, does not exist. &call bailout &end &if [EXISTS %out_sheds% -GRID] &then &do &type Output grid: %out_sheds% already exists. &call bailout &end &if [LENGTH %out_sheds%] > 13 &then &do &type Grid names must be 13 characters or less. &call bailout &end &return /* End of routine chkarg /*----------------- &routine thresh_error /*----------------- &type Flow threshold values must be an integer or real value less than or equal to 100,000 cells &return /* End of routine thresh_error /*------------------ &routine main /*------------------ /*---------------------------------------- /* Set the display environment and /* prepare hydrologic terrain analysis /* data sets. /*---------------------------------------- &echo &brief &TERMINAL 9999 DISPLAY 9999 2 position cr setwindow %source_dem% %source_dem% mape %source_dem% gridpaint %source_dem% value linear wrap gray &if [EXISTS shedoutlets -GRID] &then &do kill shedoutlets all &end &if not [EXISTS filled -GRID] &then &do fill %source_dem% filled &end &if not [EXISTS flowdirz -GRID] &then &do flowdirz = flowdirection (filled) &end &if not [EXISTS flowcountz -GRID] &then &do flowcountz = flowaccumulation (flowdirz) &end gridnodatasymbol transparent markercolor 7 linesize .025 /*-------------------------------------------------------- /* Create a map of outlet points from the stream coverage /*-------------------------------------------------------- arc nodepoint %in_streams% streamnodes points streamnodes setcell %source_dem% setwindow %source_dem% %source_dem% shedoutl = pointgrid (streamnodes) kill streamnodes all shedoutlets = snappour (shedoutl, flowcountz, %snap_dist%) %out_sheds% = watershed (flowdirz, shedoutl) kill shedoutl all gridshades %out_sheds% arcs %in_streams% &echo &off &return /* end of routine main /* /*------------ &routine usage /*------------ &type Usage: &r streamlineshed &type RUN POLYGONSHEDS.AML TO CREATE A POLYGONAL WATERSHED COVERAGE !!! &return /* End of routine usage /*----------- &routine exit /*----------- &do grd &list editshed mskgrd &if [VARIABLE %grd%] &then &do &if [EXISTS [VALUE %grd%] -GRID] &then &do KILL [VALUE %grd%] ALL &end &end &end &return /* End of routine "exit" /*-------------- &routine bailout /*-------------- &severity &error &ignore &call exit &return &error Bailing out of streamlineshed.aml...