&ARGS .fullcov .outcov .featuretype .polyitem .distances:REST /* MULTIBUFFER.AML /* by Andy Rowan rowan@crssa.rutgers.edu Revised 4/28/98 /* Creates buffers at multiple distances AND /* for a polygon input coverage, includes the original polygons /* in the output. /* This AML can be downloaded from www.crssa.rutgers.edu/people/rowan /* Written and tested with arc/info 7.1.2 on solaris 2, but it doesn't /* do anything that strange, so it will probably work on everything. /* USAGE: &run multibuffer /* {d2 d3 ...} /* If the buffer type is POLY, the coverage has to have a numeric item /* that is > 0 for all the polygons, so they can be tagged in the /* output. The name of this item is given on the command line /* (polycov-item in the usage message). If one of the coverage IDs is /* used for this, it will be retained. Otherwise, coverage id /* fields are dropped, but any additional fields in the input /* PAT will be carried over to the output. /* If the buffer type is LINE or POINT, the argument for polycov-item /* is ignored, but it still must be present in the command line as a /* placeholder. /* Buffer distances must be given in increasing order on the /* command line, and must be integers. Program will check if /* they are integers and stop if not, but it does not check if /* they aren't in order ... it just produces wrong results. /* Results are stored as an item named DISTANCE in the attribute /* table of the output coverage. The original INSIDE items from /* each buffer are also retained, renamed to INSIDE-{distance} /* Polygons from the input coverage have DISTANCE = -1. /* Intermediate coverages are deleted at the end of the run, /* but will get left behind if the program hits an error. /* Their ames all will begin with "xxmb". /* save the current setting of &messages, to restore it at the end. &setvar msgstate := [show &messages] &messages &off &info /* set the bailout routines for errors &severity &warning &routine warnbail &severity &error &routine errbail /* Now do a bunch of error checking &if [null %.distances%] &then &call returnusage &setvar .distances := [unquote %.distances%] &setvar .incov := [locase [entryname %.fullcov%]] &select %.featuretype% &when #, POLY, poly &setvar .featuretype := POLY &when ARC, arc, LINE, line &setvar .featuretype := LINE &when POINT, point &setvar .featuretype := POINT &otherwise &call returnusage &end &if ^ [exists %.fullcov% -%.featuretype%] &then &do &setvar errmess := %.featuretype% coverage %.fullcov% does not exist. &call returnerr &end &if ^ [exists %.fullcov% -CLEAN] &then &do &setvar errmess := Coverage %.incov% isn't clean. &call returnerr &end &if [exists %.outcov% -FILE] or [exists %.outcov% -DIRECTORY] &then &do &setvar errmess := Output name %.outcov% already exists. &call returnerr &end &if %.featuretype% = POLY &then &do &if %.polyitem% = # &then &setvar .polyitem := %.incov%-id &else &setvar .polyitem = [locase %.polyitem%] &if ^ [iteminfo %.fullcov% -POLYGON %.polyitem% -EXISTS] &then &do &setvar errmess := Item %.polyitem% does not exist in ~ coverage %.fullcov% &call returnerr &end &end /* Make sure the distances are positive integers &do .dist &list %.distances% &if [type %.dist%] ^= -1 or %.dist% < 1 &then &do &type Buffer distances must be positive integers &call returnusage &end &end /* Go to work! &Type Buffering %.featuretype% features in %.fullcov% at distances~ %.distances% to create %.outcov%. /* First get a unique name to use for the temporary coverages. &setvar .tmpname := [scratchname -PREFIX xxmb -DIRECTORY] &do .dist &list %.distances% &type Buffering at distance %.dist%... buffer %.fullcov% %.tmpname%%.dist% # # %.dist% # %.featuretype% round full tables SEL %.tmpname%%.dist%.PAT ALTER INSIDE INSIDE-%.dist% ~ ~ ~ ~ Q &end /* Get ready to combine the buffers. Start with the polygon coverage /* if it is one. Otherwise start empty &if %.featuretype% = POLY &then &do copy %.fullcov% %.tmpname% &if %.polyitem% = %.incov%-id or %.polyitem% = %.incov%# &then &do additem %.tmpname%.pat %.tmpname%.pat %.polyitem% 4 5 B tables sel %.tmpname%.pat resel %.tmpname%# > 1 &if %.polyitem% = %.incov%-id &then calc %.polyitem% = %.tmpname%-id &else calc %.polyitem% = %.tmpname%# q &end &end &else &do create %.tmpname% %.fullcov% build %.tmpname% poly &end &type Combining buffers: &do .dist &list %.distances% &type [unquote ' ...'%.dist%] union %.tmpname% %.tmpname%%.dist% %.tmpname%0 kill %.tmpname% all kill %.tmpname%%.dist% all dropitem %.tmpname%0.pat %.tmpname%0.pat %.tmpname%# %.tmpname%-id %.tmpname%%.dist%# %.tmpname%%.dist%-id end rename %.tmpname%0 %.tmpname% &end additem %.tmpname%.pat %.tmpname%.pat DISTANCE 4 5 b tables sel %.tmpname%.pat /* first is it in the original polygon &if %.featuretype% = POLY &then &do resel %.polyitem% > 0 calc distance = -1 &end /* now move out each distance and see if it's in. &do .dist &list %.distances% asel resel distance = 0 resel inside-%.dist% = 100 calc distance = %.dist% &end q &type Running final dissolve. dissolve %.tmpname% %.outcov% #ALL kill %.tmpname% all &messages %msgstate% &RETURN /* END OF MAIN PROGRAM /* error handling subroutines &routine returnusage &messages %msgstate% &return &warning Usage: &run multibuffer ~ {d2...} &routine returnerr &messages %msgstate% &return &error %errmess% &routine warnbail &messages %msgstate% &return &warning &routine errbail &messages %msgstate% &return &error