/* SB.AML (ArcPlot) /* Draws an annotated scale bar. /* /* Usage: /* /* SB ~ /*{linesymbol} {shadesymbol} /* /*Modified for GRC use in April 1997, J.D. Harlan /*Created by Bob Hyatt 4/27/92 /* Arguments: /* /* xpos x-coordinate of the center of the bar. /* ypos y-coordinate of the bottom of the bar. /* height height of scale bar (inches). /* bars number of bar increments. /* bar_length unit length of each bar increment. /* linesymbol linesymbol used to draw scalebar. /* shadesymbol polygon shade symbol. /* /* Example: /* /* &run sb 5.0 2.0 0.2 3 100feet 2400 1 1 /* /* Regardless of coverage units, produces a scalebar with 3 /* increments of 100 feet each with its lower center at /* coordinate (10,25). Also annotates the scalebar. /* /* /* Internal variables: /* /* barlength = length of one bar in ground units. /* scaled_barlength = map length of on bar increment (inches). /* x1, y1, x2, y2, y3 = points locating the corners of boxes /* or ends of lines. /* size = calculated text size. /* scaled_width_total = calculated total length of scalebar. /* scaled_width_segment = calculated length of each increment. /* fine_scaled_width_segment = length of subdivided increment /* (scaled_width_segment/10). /* measure = text string used to annotate increments. /* Get arguments and go to work. &args xpos ypos height incs unit linesymbol sh_symbol /* Set variable to enable the previous environment to be restored. &s echo [show &echo] &echo &on &if [null %xpos%] &then &do &type Usage : sb {linesymbol} {shadesymbol} &return Example: &r sb.aml 7 .5 .1 10 1miles 1 1 &end /*Set Scale &s scalefactor [show mapscale] /* Set text characteristics. textfont times textquality kern textspacing 1.2 /* Set line symbol. lineset plotter.lin &if [null %linesymbol%] &then &s linesymbol 1 &if [type %linesymbol%] > 0 &then &do &if %linesymbol% = # &then &s linesymbol 1 &else &return &warn sb.aml: Invalid linesymbol: %linesymbol% &end linesymbol %linesymbol% linepen [calc 0.08 * %height%] square miter /* Set shade symbol. shadeset colornames &if [null %sh_symbol%] &then &s sh_symbol 29 shadesymbol %sh_symbol% /* Check validity of unit bar length. &s unit [locase %unit%] &s pos 1 &if [type [substr %unit% 1 %pos%]] > 0 &then &do &type sb.aml: Invalid unit bar length (%unit%). This parameter must be in the form: &return NUUNITS where N is an integer and UNITS are the unit type (eg. 100feet). &end &do &while [type [substr %unit% 1 %pos%]] < 0 and %pos% < [length %unit%] &s pos %pos% + 1 &end /* Extract components of bar_length parameter. &s barlength [substr %unit% 1 [calc %pos% - 1]] &s unitname [upcase [substr %unit% %pos%]] /* Set scaling parameters. /* Note: Constants are the number of inches in one measurement unit. &select %unitname% &when FT, FOOT, FEET &s scaled_barlength %barlength% / %scalefactor% * 12 &when MI, MILE, MILES &s scaled_barlength %barlength% / %scalefactor% * 63360 &when M, METER, METERS &s scaled_barlength %barlength% / %scalefactor% * 39.370078 &when KM, KILOMETER, KILOMETERS &s scaled_barlength %barlength% / %scalefactor% * 39370.078 &otherwise &do &type Invalid unit bar length parameter: %unit%. &type The unit bar length parameter must be in the form NUNITS where: &type N is an integer, and UNITS are ft, foot, feet, mi, mile, miles, &type m, meter, meters, km, kilometer, or kilometers (eg. 100feet). &return &end &end /* Write scale statement. &s x1 %xpos% &s y1 %ypos% + %height% * 1.4 &s size %height% * 0.5 &if %size% < 0.08 &then &s size 0.08 textsize %size% /*&if %unitname% = FEET and %style% = 1 &then /*&s string Scale: 1" = [round [calc %scalefactor% / 12]]' /*&else /*&s string Scale 1:%scalefactor% /*move %x1% %y1% /*text [quote %string%] lc /* Calculate variables for scalebar construction. &s scaled_width_total [calc %incs% * %scaled_barlength%] &s scaled_width_segment [calc %scaled_width_total% / %incs%] &s fine_scaled_width_segment [calc %scaled_width_segment% / 10] &s x1 [calc %xpos% - %scaled_width_total% / 2] &s x2 [calc %x1% + %fine_scaled_width_segment%] &s y1 %ypos% &s y3 [calc %y1% + %height% / 2] mbegin /* Draw and shade fine increments in first box. &do i = 1 &to 5 patch %x1% %y1% %x2% %y3% box %x1% %y1% %x2% %y3% &s x1 %x2% + %fine_scaled_width_segment% &s x2 %x1% + %fine_scaled_width_segment% &end /* Reset variables to draw larger increements. &s x1 %xpos% - %scaled_width_total% / 2 &s y1 %ypos% &s x2 %x1% + %scaled_width_segment% &s y2 %ypos% + %height% &s y3 %y1% + %height% / 2 /* Draw, shade and annotate bar increments. &do i = 1 &to %incs% &if %i% = 1 &then &goto patched &if [mod %i% 2] <> 0 &then patch %x1% %y1% %x2% %y3% &else patch %x1% %y3% %x2% %y2% /*************** &label patched /*************** &s measure ( %i% - 1 ) * %barlength% move %x1% [calc %ypos% - 1.3 * %size%] text [quote %measure%] lc box %x1% %y1% %x2% %y2% line %x1% %y3% %x2% %y3% &s x1 %x2% &s x2 %x2% + %scaled_width_segment% &end /* do statement /* Add length annotation at right end of last bar. &s measure ( %i% - 1 ) * %barlength% move %x1% [calc %ypos% - 1.3 * %size%] text [quote %measure%] lc /* Add unit annotation. move %xpos% [calc %ypos% - 2.6 * %size%] text %unitname% lc mend %unit% /* Restore &echo to its previous value and return to calling program. &echo %echo% &return *******************************End of AML***********************************