/* Program: img_clip.aml /* /* Purpose: Creates a new sub-image clipped from an input image, based on /* the extent of either a clip coverage or an interactive zoom. /* /* Usage: &r img_clip /* Ex: &r img_clip golden.tif golden_clip.tif goldennt /* &r img_clip mor.bil mor_cl.bil * /* /* Input: Any image supported by Arc /* /* Output: Output image is same cellsize as input image, but is clipped to /* the extent of the POLYGON clipcover. /* /* Notes: Run this program without arguments to see the usage and examples. /* Program uses ArcEdit to zoom in to clip area, then uses Arc:RECTIFY /* to create the subset image. /* /* History: JKosovich USGS 09/10/97 Original coding /* JKosovich USGS 03/31/98 Modified to allow interactive clipping /* JKosovich USGS 04/09/98 Fixed SEARCH usage /* JKosovich USGS 05/19/98 Fixed for ARC Grid input source /* /******************************************************************************* /* &args inimage outimage clipopt &severity &error &routine bailout &s prog = [ENTRYNAME %aml$file% -NOEXT -FILE] /* current AML being run &if [NULL [SHOW &watch]] &then &watch %prog%.watch /* /***** Check for correct usage and correct argument types ***** /* &if [NULL %clipopt%] &then &do /* /***** Determine ARC/INFO version for supported image formats ***** /* &call find_formats &s error_case = 1 &call error_cond &end /* Set terminal type for later popups &if [NULL [EXTRACT 1 [SHOW &terminal]]] &then &terminal 9999 &if ^ [EXISTS %inimage% -FILE] & ^ [EXISTS %inimage% -GRID] &then &do &s error_case = 2 &call error_cond &end &else &if ^ [EXISTS %inimage% -IMAGE] &then &do &s error_case = 3 &call error_cond &end &if [EXISTS %outimage% -FILE] &then &do &s error_case = 4 &call error_cond &end /* /***** If input image is a Grid, set flag (clipping commands are different)***** /* &s gridin = .FALSE. &if [EXISTS %inimage% -GRID] &then &s gridin = .TRUE. /* /***** Clip using clipcoverage ***** /* &if [SEARCH %clipopt% *] = 0 &then /* if no *, then treat as clipcover &do &s clipcov = %clipopt% &if ^ [EXISTS %clipcov% -COVER] &then &do &s error_case = 5 &call error_cond &end &else &if ^ [EXISTS %clipcov% -POLYGON] &then &do &s error_case = 6 &call error_cond &end &else &call clip_cover /* Uses cover to clip &end /* /***** Clip interactively on-screen ***** /* &else /* "*" found in string &call clip_screen /* /***** All finished ***** /* &if [EXISTS xxmsg -FILE] &then &s dok = [DELETE xxmsg -FILE] &type &type &type *** %prog%.aml successful. Output image %outimage% created. &type &type &return /* /*------------------------------------------------------------------------------ /*------------------------------ ROUTINE LIST -------------------------------- /*------------------------------------------------------------------------------ /* /* /*----------------- &routine CLIP_COVER /*----------------- /* Clip image using clipcover &type &type *** Clipping image... &if %gridin% &then LATTICECLIP %inimage% %clipcov% %outimage% MINIMUM &else RECTIFY %inimage% %outimage% NEAREST # %clipcov% &return /*------------------ &routine CLIP_SCREEN /*------------------ /* Clip image visually &type &type *** Please wait for image to draw on screen... DISPLAY 0 &if [UPCASE [SHOW PROGRAM]] ^= ARCEDIT &then ARCEDIT DISPLAY 9999 3 MAPEXTENT IMAGE %inimage% IMAGE %inimage% DRAW /* Create temp message file for zooming in approximately &if [EXISTS xxmsg -FILE] &then &s dok = [DELETE xxmsg -FILE] &s unit = [OPEN xxmsg ook -WRITE] &s wok = [WRITE %unit% ' '] &s wok = [WRITE %unit% 'Use PAN/ZOOM button (Extent option) in upper left'] &s wok = [WRITE %unit% 'to zoom in to an APPROXIMATE image extent which is'] &s wok = [WRITE %unit% 'slightly larger than the desired clipping area.'] &s wok = [WRITE %unit% ' '] &s wok = [WRITE %unit% 'Press QUIT when done zooming. You will then be'] &s wok = [WRITE %unit% 'prompted to select the FINAL image clipping box.'] &s wok = [WRITE %unit% ' '] &s cok = [CLOSE %unit%] &popup xxmsg /* Refine the zoom until user indicates correct extent &messages &popup &do &while ^ [QUERY 'Is the image extent correct (NO to zoom further)' .FALSE.] MAPEXTENT * DRAW &end &messages &on &s i_mapextent = [SHOW MAPEXTENT] &s i_xmin = [EXTRACT 1 [SHOW MAPEXTENT]] &s i_ymin = [EXTRACT 2 [SHOW MAPEXTENT]] &s i_xmax = [EXTRACT 3 [SHOW MAPEXTENT]] &s i_ymax = [EXTRACT 4 [SHOW MAPEXTENT]] &s i_dx = [CALC %i_xmax% - %i_xmin%] &s i_dy = [CALC %i_ymax% - %i_ymin%] QUIT /* Clip to the final mapextent &type &type *** Clipping image... &if %gridin% &then GRIDCLIP %inimage% %outimage% %i_mapextent% &else RECTIFY %inimage% %outimage% NEAREST # BOX %i_mapextent% &return /*------------------- &routine FIND_FORMATS /*------------------- /* Find supported image formats &s arcver = [EXTRACT 1 [SHOW VERSION]] /* eg. 7.0.4, 7.1, 7.1.1 &s arcver1 = [BEFORE %arcver% .] /* eg. 7 &if %arcver1% < 7 &then &return &error \*** NOTE: Must use Arc version 7.0 or newer (%arcver%)\\ &s arcver2 = [SUBSTR [AFTER %arcver% .] 1 1] /* digit after the 7, eg. 0, 1 &if %arcver2% = 0 & %arcver1% = 7 &then /* if 7.0.3, 7.0.4, etc. &do &s inlist1 = TIFF, BIL, BIP, BSQ, RLC, Arc GRID, &s inlist2 = SUNRASTER, ERDAS, IMAGINE, GRASS &end &else &if %arcver2% > 0 | %arcver1% > 7 &then /* if 7.1, 7.1.1, 8.0, etc. &do &s inlist1 = TIFF, JPEG, BIL, BIP, BMP, BSQ, RLC, &s inlist2 = SUNRASTER, ERDAS, IMAGINE, GRASS, Arc GRID &end &return /*------------------ &routine ERROR_COND /*------------------ /* &severity &error &ignore /* not routine bailout, since bailout could delete /* a pre-existing out_image if error_cond bombs &messages &on &type &type &type *************** PROGRAM [TRANSLATE %prog%] HALTED ***************** /* &if %error_case% = 1 &then /***** Incorrect usage &do &type USAGE: &r %prog% &type Ex: &r %prog% golden.tif golden_clip.tif goldennt (clipcov usage) &type &r %prog% mor.bil mor_cl.bil * (screen zoom usage) &type &type Output resolution is the same as input resolution. &type If used, CLIP_COVER must have POLYGON topology. &type "*" usage draws on screen, allows visual clipping. &type Program works on any ARC/INFO-supported image format: &type %inlist1% &type %inlist2% &type &end &if %error_case% = 2 &then /***** If image file/grid not found &type Image %inimage% does not exist!!! &if %error_case% = 3 &then /***** If image entered is not valid image &type Image format of %inimage% is not supported by ARC/INFO!!! &if %error_case% = 4 &then /***** If output already exists &type Output image %outimage% already exists!!! &if %error_case% = 5 &then /***** If clip cover not found &type Clip coverage %clipcov% does not exist!!! &if %error_case% = 6 &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 *********************************************************\\ /* &return; &return &error /*------------------ &routine BAILOUT /*------------------ /* &severity &error &ignore &messages &on &if [UPCASE [SHOW PROGRAM]] = ARCEDIT &then QUIT &if [EXISTS xxmsg -FILE] &then &s dok = [DELETE xxmsg -FILE] &if [VARIABLE outimage] &then &do &if [EXISTS %outimage% -FILE] &then &s dok = [DELETE %outimage% -FILE] &end &type \*** Error occurred at line %aml$errorline% in %aml$errorfile%\ /* &return; &return &error