/* Program: elev2hillsh.aml /* /* Purpose: Creates a hillshade grid from an input elevation grid, with /* options to rotate and clip output. /* /* Usage: &r elev2hillsh /* /* {clip_cover} /* Ex: &r elev2hillsh gol_elev gol_hillsh 10 315 35 5 0 1.682 golnt /* /* Output: Output is a hillshaded elevation grid with cellsize of /* , optionally clipped to the extent of {clip_cover}, /* rotated an angle of (positive angle = clockwise, /* negative = counter, can enter 0 for no rotation), with /* shaded relief parameters: azimuth of , altitude of /* , and vertical exaggeration of , /* smoothed with a square-kernelled filter of cells. /* /* Notes: Run this program without arguments to see the usage and examples. /* /* The is the size, in cells, of the square /* filter which will be passed over the hillshade grid (use 0 for no /* smoothing, use 10 for significant smoothing, any integer okay). /* For example, entering 3 will pass a 3x3-cell filter over the output. /* If an angle of 0 is entered, the hillshade grid will not be rotated. /* /* History: JKosovich 02/19/97 Coding for abandoned mine lands, based on /* dem2grid.aml. /* JKosovich 09/10/97 Modified header /* JKosovich 11/06/97 Cleans up leftover Grid trash (xyxy001...) /* JKosovich 02/04/98 Added argument /* JKosovich 05/14/98 Turned watch file off (NT doesn't overwrite /* watch file if file is still active!!) /* /******************************************************************************* /* &args inelevgrd outshgrid outshres az alt ve xy angle clipcov &severity &error &routine bailout &s prog = [ENTRYNAME %aml$file% -NOEXT -FILE] /* current AML being run &watch %prog%.watch /* /***** Check for correct usage and correct argument types ***** /* &if [NULL %angle%] &then &do &s error_case = 1 &call error_cond &end &if [LENGTH %outshgrid%] > 12 &then &do &s error_case = 2 &call error_cond &end &do xx &list outshres ve angle /* these can be int or real &if [TYPE [VALUE %xx%]] > 0 &then &do &s error_case = 3 &call error_cond &end &end &do xx &list alt az xy /* these can only be integer &if ^ [NULL [VALUE %xx%]] &then &do &if [TYPE [VALUE %xx%]] ^= -1 &then &do &s error_case = 4 &call error_cond &end &end &end /* /***** Check for existence of input grid and clipcover ***** /* &if ^ [EXISTS %inelevgrd% -GRID] &then &do &s error_case = 5 &call error_cond &end &if ^ [NULL %clipcov%] &then &do &s clip = .TRUE. &if ^ [EXISTS %clipcov% -COVER] &then &do &s error_case = 6 &call error_cond &end &else &if ^ [EXISTS %clipcov% -POLYGON] &then &do &s error_case = 7 &call error_cond &end &end &else &s clip = .FALSE. /* /***** Set variables ***** /* &s resample = .FALSE. &s convint = .FALSE. &s rotate = .TRUE. /* Don't rotate if 0 ang &if %angle% = 0 &then &s rotate = .FALSE. &if %angle% = 0.0 &then &s rotate = .FALSE. &s smooth = .TRUE. /* Don't smooth if 0 xy &if %xy% = 0 &then &s smooth = .FALSE. /* /***** Determine input grid's resolution, resample and convert temp grid ***** /***** to integer if necessary ***** /* &describe %inelevgrd% &s ingridres = %grd$dx% /* resolution of incoming elev grid &s ingridtype = %grd$type% /* type of grid: 1 = int, 2 = floating pt. &if %ingridres% ^= %outshres% &then &s resample = .TRUE. &if %ingridtype% = 2 &then &s convint = .TRUE. &if %resample% | %convint% &then &do DISPLAY 0 GRID &if [EXISTS xxgrd1 -GRID] &then KILL xxgrd1 ALL &if %resample% = .TRUE. & %convint% = .FALSE. &then xxgrd1 = RESAMPLE(%inelevgrd%,%outshres%) &else &if %resample% = .FALSE. & %convint% = .TRUE. &then xxgrd1 = INT(%inelevgrd%) /* Convert to integer, much smaller file size! &else &if %resample% = .TRUE. & %convint% = .TRUE. &then xxgrd1 = INT(RESAMPLE(%inelevgrd%,%outshres%)) QUIT &end &if [EXISTS xxgrd1 -GRID] &then PROJECTCOPY GRID %inelevgrd% GRID xxgrd1 &else COPY %inelevgrd% xxgrd1 /* /***** Clip grid to %clipcov% extent ***** /* &if [EXISTS xxgrd2 -GRID] &then KILL xxgrd2 ALL &if %clip% &then LATTICECLIP xxgrd1 %clipcov% xxgrd2 MINIMUM 1 &if [EXISTS xxgrd2 -GRID] &then &do PROJECTCOPY GRID xxgrd1 GRID xxgrd2 KILL xxgrd1 ALL &end &else RENAME xxgrd1 xxgrd2 /* /***** Rotate grid to due N-S orientation for plotting ***** /* &if [EXISTS xxgrd3 -GRID] &then KILL xxgrd3 ALL &if %rotate% &then GRIDROTATE xxgrd2 xxgrd3 %angle% &if [EXISTS xxgrd3 -GRID] &then &do PROJECTCOPY GRID xxgrd2 GRID xxgrd3 KILL xxgrd2 ALL &end &else RENAME xxgrd2 xxgrd3 /* /***** Apply HILLSHADE parameters ***** /* &if [EXISTS %outshgrid% -GRID] &then KILL %outshgrid% ALL DISPLAY 0 GRID &if %smooth% &then %outshgrid% = HILLSHADE(FOCALMEAN(xxgrd3,RECTANGLE,%xy%,%xy%),%az%,%alt%,SHADE,%ve%) &else %outshgrid% = HILLSHADE(xxgrd3,%az%,%alt%,SHADE,%ve%) QUIT &if [EXISTS %outshgrid% -GRID] &then &do PROJECTCOPY GRID xxgrd3 GRID %outshgrid% KILL xxgrd3 ALL &type &type &type *** %prog% successful. Shaded relief grid is %outshgrid% &type &type &end &else &do &type &type &type *** %prog% ERROR: Shaded relief grid %outshgrid% not created!!! &type *** Last temporary grid made was: xxgrd3. &type &type &end /* Clean up Grid junk &do n = 1 &to 9 &if [EXISTS xyxy00%n% -GRID] &then KILL xyxy00%n% ALL &end /* /* &watch &off &return /* /* /*------------------------------------------------------------------------------ /*------------------------------ ROUTINE LIST -------------------------------- /*------------------------------------------------------------------------------ /* /* /*------------------ &routine ERROR_COND /*------------------ /* &severity &error &routine bailout &if [UPCASE [SHOW PROGRAM]] = TABLES &then QUIT &messages &on /* Clean up Grid junk &do n = 1 &to 9 &if [EXISTS xyxy00%n% -GRID] &then KILL xyxy00%n% ALL &end &type &type &type *************** PROGRAM [TRANSLATE %prog%] HALTED ***************** /* &if %error_case% = 1 &then /***** Incorrect usage &do &type USAGE: &r %prog% &type &type {clip_cover} &type Ex: &r %prog% gol_elev gol_hillsh 10 315 35 5 0 1.682 golnt &type &r %prog% g6_elev g6_hillsh 10 310 40 4 9 0 &type &type ELEVATION and HILLSHADE GRID NAMES must be 12 characters or less. &type OUTPUT HILLSHADE RESOLUTION is in ground units (eg. meters). &type AZIMUTH is whole degrees clockwise from North, North being 0. &type ALTITUDE is whole degrees above the horizon, horizon being 0. &type VERTICAL EXAGGERATION can be integer or whole, typically 5 or less. &type SMOOTHING KERNEL: use 0 for no hillshade smoothing, any integer OK. &type Use positive ANGLE to rotate hillshade grid clockwise to grid north, &type Use negative ANGLE to rotate hillshade grid counterclockwise. &type Use ANGLE of 0 for no rotation. &type If clipping, CLIP COVER must have POLYGON topology. &end &if %error_case% = 2 &then /***** If output grid name too long &type Output grid name is too long - must be 12 characters or less!!! &if %error_case% = 3 &then /***** Argument must be int or real &type Argument %xx% must be an integer or real value!!! &if %error_case% = 4 &then /***** Argument must be integer &type Argument %xx% must be an integer value!!! &if %error_case% = 5 &then /***** If input elev grid not found &type Input elevation grid %inelevgrd% does not exist!!! &if %error_case% = 6 &then /***** If clip cover not found &type Clip coverage %clipcov% does not exist!!! &if %error_case% = 7 &then /***** If clip cover not a POLY cover &type Clip coverage %clipcov% does not have POLYGON topology!!! /* &type Process halted [DATE -DOW] [DATE -CAL] [DATE -AMPM] &type ********************************************************* &type /* &watch &off &return; &return &error /* /* /*------------------ &routine BAILOUT /*------------------ /* &severity &error &ignore /* Clean up Grid junk &do n = 1 &to 9 &if [EXISTS xyxy00%n% -GRID] &then KILL xyxy00%n% ALL &end &type &type *** Error occurred at line %aml$errorline% in %aml$errorfile% &watch &off &return; &return &error /* /*