/* Program: dem2grid.aml /* /* Purpose: Creates an ARC grid from a DEM file. Contains options to /* change output cellsize, integer/real type, Z units, and /* Y-coordinate shift. /* /* Usage: &r dem2grid {outgrid_xy_res} /* {INT | FLOAT} {FEET | METERS} {Y_shift} /* Ex: &r dem2grid gol.dem gol_elev /* &r dem2grid scapoose.dem scapelev 10 float feet /* &r dem2grid scapoose.dem scapelev # # meters /* &r dem2grid tor.dem tor_el # int # -4000000 /* /* Output: By default, a raw INTeger elevation grid having the same x,y /* resolution and Z units as the input DEM is created. /* /* If given, the output grid resolution {outgrid_res} will be enforced. /* The {INT | FLOAT} keywords can be used to force the output grid to /* be integer or floating point. Likewise, the Z units of the output /* grid can be forced to be FEET or METERS, regardless of the input /* DEM vertical units. The value entered for {Y_shift} will be /* added to the Y coordinates. /* /* Notes: Run this program without arguments to see the usage and examples. /* Use the "#" character to skip optional arguments. /* /* For applications using SLOPE grids, the Z units must match the /* horizontal x.y units before the (SLOPE) function is applied. /* Use this AML to output elevation grids in Z-Meters to match the /* typical UTM meters in x.y. /* /* History: JKosovich 09/10/97 Coding for Middle Rio Grande slope project, /* original dem2grid.aml renamed dem2hillsh.aml. /* JKosovich 01/13/98 Turned watch off, loop to clean up grid junk /* JKosovich 01/21/98 Minor modification to a comment line /* /******************************************************************************* /* &args indem outelevgrd outres valtype zunits yshift &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 %outelevgrd%] &then &do &s error_case = 1 &call error_cond &end &if [LENGTH %outelevgrd%] > 12 &then &do &s error_case = 2 &call error_cond &end &if ^ [NULL %outres%] &then /* Output resolution &do &if [TYPE %outres%] > 0 &then /* If not int or real number &do &if %outres% = # &then &s resample = .FALSE. &else &do &s error_case = 3 &call error_cond &end &end &else &if %outres% < 0 &then &do &type \*** NOTE: Negative cellsize is invalid. Using absolute value...\ &s outres = [ABS %outres%] &s resample = .TRUE. &end &else &s resample = .TRUE. &end &else &do &s resample = .FALSE. &s checktype = .FALSE. &s convunits = .FALSE. &end &s valtype = [UPCASE %valtype%] /* Value type &if ^ [NULL %valtype%] &then &do &if %valtype% = # &then &s valtype = INT &else &if %valtype% ^ in {'INT','FLOAT'} &then /* required keywords &do &s error_case = 4 &call error_cond &end &else &type \*** Please wait... &end &else &s valtype = INT &if %valtype% = INT &then &s outtype = 1 /* to match grd$type variable &if %valtype% = FLOAT &then &s outtype = 2 &s zunits = [UPCASE %zunits%] /* Z units &if ^ [NULL %zunits%] &then &do &if %zunits% = # &then &s convunits = .FALSE. &else &if %zunits% ^ in {'FEET','METERS'} &then /* required keywords &do &s error_case = 5 &call error_cond &end &else &s convunits = .TRUE. &end &else &s convunits = .FALSE. &if ^ [NULL %yshift%] &then /* Y shift &do &if [TYPE %yshift%] > 0 &then /* If not int or real number &do &if %yshift% = # &then &s shift = .FALSE. &else &do &s error_case = 6 &call error_cond &end &end &else /* if a number &do &s shift = .TRUE. &if %yshift% = 0 &then &s shift = .FALSE. &end &end &else &s shift = .FALSE. /* /***** Check for existence of input file ***** /* &if ^ [EXISTS %indem% -FILE] &then &do &s error_case = 7 &call error_cond &end /* /***** Set terminal ***** /* &if [NULL [EXTRACT 1 [SHOW &terminal]]] &then &terminal 9999 DISPLAY 0 /* /******************************************************************************* /*************** All done checking, begin the real work ********************** /******************************************************************************* /* /* /***** Convert DEM to Arc grid ***** /***** default, Arc brings in as floating point grid, even if integer DEM ***** /* &if [EXISTS %outelevgrd% -GRID] &then KILL %outelevgrd% ALL &if [EXISTS xxgrd1 -GRID] &then KILL xxgrd1 ALL &if [EXISTS xxgrd2 -GRID] &then KILL xxgrd2 ALL &if [EXISTS xxgrd3 -GRID] &then KILL xxgrd3 ALL &type \*** Converting DEM file into a grid... DEMLATTICE %indem% %outelevgrd% USGS /* /***** Check for existence of output grid from DEMLATTICE ***** /* &if ^ [EXISTS %outelevgrd% -GRID] &then &do &s error_case = 8 &call error_cond &end /* /***** Determine parameters of input ***** /* &describe %outelevgrd% &s indemres = %grd$dx% /* resolution of incoming DEM = grid res &s gridz = [UPCASE %prj$zunits%] /* Z units: FEET or METERS &s xmin = %grd$xmin% /* orig X min coord &s ymin = %grd$ymin% /* orig Y min coord /* /***** Resample grid ***** /* &if %resample% &then &do &if %indemres% ^= %outres% &then &do &if [UPCASE [SHOW PROGRAM]] ^= GRID &then GRID &type \*** Resampling to %outres%... xxgrd1 = RESAMPLE(%outelevgrd%,%outres%) &end &end &if [EXISTS xxgrd1 -GRID] &then &do ARC PROJECTCOPY GRID %outelevgrd% GRID xxgrd1 &messages &off KILL %outelevgrd% ALL &messages &on RENAME xxgrd1 %outelevgrd% &end /* /***** Convert Z units if applicable ***** /* &if %convunits% &then &do &if %gridz% ^= %zunits% &then &do &if %gridz% = FEET &then &s convfactor = 0.3048 /* ft->m &if %gridz% = METERS &then &s convfactor = 3.2808 /* m->ft &if [UPCASE [SHOW PROGRAM]] ^= GRID &then GRID &type \*** Converting Z units to %zunits%... xxgrd2 = %outelevgrd% * %convfactor% &end &end &if [EXISTS xxgrd2 -GRID] &then &do ARC PROJECTCOPY GRID %outelevgrd% GRID xxgrd2 ARC PROJECTDEFINE GRID xxgrd2 ZUNITS %zunits% PARAMETERS &if [UPCASE [SHOW program]] = PRJDEF &then END &messages &off KILL %outelevgrd% ALL &messages &on RENAME xxgrd2 %outelevgrd% &end /* /***** INT or FLOAT function ***** /* &describe %outelevgrd% &s gridtype = %grd$type% /* type of grid: 1 = int, 2 = floating pt. &if %gridtype% ^= %outtype% &then &do &if [UPCASE [SHOW PROGRAM]] ^= GRID &then GRID &type \*** Converting grid to %valtype%... xxgrd3 = %valtype%(%outelevgrd%) &end &if [EXISTS xxgrd3 -GRID] &then &do ARC PROJECTCOPY GRID %outelevgrd% GRID xxgrd3 &messages &off KILL %outelevgrd% ALL &messages &on RENAME xxgrd3 %outelevgrd% &end &if [UPCASE [SHOW PROGRAM]] = GRID &then QUIT /* /***** Apply Yshift ***** /* &if %shift% &then &do &type \*** Applying Yshift of %yshift% to grid... &s new_y = [CALC %ymin% + %yshift%] GRIDSHIFT %outelevgrd% xxgrd4 %xmin% %new_y% &if [EXISTS xxgrd4 -GRID] &then &do PROJECTCOPY GRID %outelevgrd% GRID xxgrd4 PROJECTDEFINE GRID xxgrd4 YSHIFT %yshift% PARAMETERS &if [UPCASE [SHOW program]] = PRJDEF &then END &messages &off KILL %outelevgrd% ALL &messages &on RENAME xxgrd4 %outelevgrd% &end &end /* /***** Clean up Grid junk ***** /* &messages &off &all &do n = 1 &to 9 &if [EXISTS xyxy00%n% -GRID] &then KILL xyxy00%n% ALL &end &messages &on &type \\*** Program %prog%: Successful creation of grid %outelevgrd%.\\ /* &watch &off &return /* /* /*------------------------------------------------------------------------------ /*------------------------------ ROUTINE LIST -------------------------------- /*------------------------------------------------------------------------------ /* /* /*------------------ &routine ERROR_COND /*------------------ /* &severity &error &routine bailout &if [UPCASE [SHOW PROGRAM]] = TABLES &then QUIT &messages &on &type \\********************* PROGRAM %prog% HALTED ********************* /* &if %error_case% = 1 &then /***** Incorrect usage &do &type USAGE: &r %prog% {outgrid_xy_res} &type {INT | FLOAT} {ZUnits: FEET | METERS} {Y_shift} &type &type Ex: &r %prog% gol.dem gol_elev &type &r %prog% scapoose.dem scapelev 10 float feet -5000000 &type &r %prog% scapoose.dem scapelev # # meters &type &r %prog% tor.dem tor_el # int # -4000000 &type &type By default, a raw integer elevation grid having the same x,y &type resolution and Z units as the input DEM is created. &type Use the "#" character to skip optional arguments. &type OUTPUT ELEVATION GRID NAME must be 12 characters or less. &type OUTPUT ELEVATION GRID RESOLUTION is in ground x,y units (eg. meters). &type Use the INT | FLOAT and FEET | METERS keywords (upper or lower case) &type to enforce these options on the output grid. &type The YSHIFT value will be ADDED to the grid's Y coordinates. Use &type a negative value to subtract a yshift. &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 %outres% must be an integer or real value!!! &if %error_case% = 4 &then /***** Incorrect keywords &type Argument %valtype% must be INT or FLOAT!!! &if %error_case% = 5 &then /***** Incorrect keywords &type Argument %zunits% must be FEET or METERS!!! &if %error_case% = 6 &then /***** Yshift must be int or real &type Argument %yshift% must be an integer or real value!!! &if %error_case% = 7 &then /***** If dem file not found &type DEM file %indem% does not exist!!! &if %error_case% = 8 &then /***** Output grid not created by DEMLATTICE &type Error in creating initial grid!!! /* &type Process halted [DATE -DOW] [DATE -CAL] [DATE -AMPM] &type **********************************************************************\ /* &watch &off &return; &return &error /* /* /*------------------ &routine BAILOUT /*------------------ /* &severity &error &ignore &messages &on &if [UPCASE [SHOW PROGRAM]] = GRID &then QUIT &if [UPCASE [SHOW program]] = PRJDEF &then END &type \*** Error occurred at line %aml$errorline% in %aml$errorfile% &watch &off &return; &return &error /* /*