rtTransPres2c.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# rtTransPres2c.qry
# This is a sample script for drawing a dashed line symbol for a
# right-lateral transpressional fault.  Triangle symbols are
# drawn on the upthrown (left) side of the fault line.
# If this is the wrong side for an individual line, use
# the Spatial Data Editor to reverse its start and end points.
# Strike-slip arrows are drawn centered between the pair of
# triangles nearest to the center of the line.
# Version March 2008
# Requires TNTmips 2006:72 or later.
# Version 30 April 2008
# Improved drawing of displacement arrows so they look better for
# wider line widths.  Arrow offset determined from line width.
# Special drawing instructions added for LegendView.
numeric red, green, blue;
numeric triMap, triWidth, halfTri, heightFac, height, spacing, halfSpacing, dist;
numeric arrowLengthMap, arrowSize, wingSizeFac, wingSize, angle, offsetFac, arrowOffset;
numeric triInt, cumDash;
numeric arrowsDrawn;		# flag to indicate whether arrow symbol has been drawn
numeric lineCheck;
class RVC_GEOREFERENCE vGeoref;
class SR_COORDREFSYS vectCRS;
class STRING coordUnit$;
###################### Set Parameters ##############################
# red, green, blue variables define the color of the line
red = 255;			green = 0;			blue = 0;
# This variable defines the denominator of the intended map scale.
# It is used as the basis for defining line width and symbol size
# and spacing.
# Example: for 1:24,000 map scale, Scale = 24000
scale = 24000;
# These variables set the dimensions of the triangle symbols.
# TriMap is the desired triangle width in mm, assuming vector
# coordinates are in meters:
triMap = 3;
heightFac = 0.6;		# height of triangle as fraction of width
# This variable sets interval between triangles in number of dashes.
triInt = 3;			# three dashes (plus half dash spaces) between triangles
# This variable controls the width of the lines.
# WidthMap is the desired map width in mm, assuming vector
# coordinates are in meters.
widthMap = 0.6;
# This variable sets the length of the arrows
# ArrowLengthMap is the desired arrow length in mm, assuming vector
# coordinates are in meters:
arrowLengthMap = 6;
# This variable controls the sweep angle of the arrow in degrees
angle = 30;	 # 30 degree angle
# This variable sets the length of the side of the arrowhead as a
# fraction of the arrow length
wingSizeFac = 0.4;
# This variable controls how far from the base line to draw arrows
# as a multiple of line width
offsetFac = 2.5;
#######################  Compute Derived Values ########################
# Check if vector has geographic coordinates (units of degrees instead of meters)
# and if so adjust scale factor to draw symbols of appropriate size.
Vect.GetDefaultGeoref(vGeoref);
vectCRS = vGeoref.GetCoordRefSys();
if (vectCRS.IsProjected() <> 1) {
	if (vectCRS.IsLocal() <> 1) {
		scale = scale * 0.000009;
		}
	}
else {	# CRS is projected; check coordinate units to adjust scale
	# get coordinate unit from the first axis of the planar coordinate system
	coordUnit$ = vectCRS.Coordsys.GetAxis(1).Unit.GetSymbol();
	scale = scale * GetUnitConvDist("m", coordUnit$);
	}
# set final dimensions for drawing
if (DrawingLegendView == 1) {		# set dimensions for LegendView based on sample size
	triWidth = 0.15 * SampleRect.GetWidth();
	width = 0.1 * SampleRect.GetHeight();
	arrowSize = 0.4 * SampleRect.GetWidth();
	}
else {		# set dimensions for drawing elements in View using scale
	scale = scale / 1000;	# conversion from meters to millimeters
	triWidth = triMap * scale;
	width = widthMap * scale;
	arrowSize = arrowLengthMap * scale;
	}
# Compute final triangle dimensions
height = heightFac * triWidth;	# height of triangle as a fraction of width
halfTri = triWidth * 0.5;
# Compute distance between triangles based on interval (dashes plus half-dash spaces)
spacing = (triInt * 1.5 * triWidth) + 0.5 * triWidth;		# half-dash space for each dash plus one more half-dash space
# Distance derived from spacing to use as origin for drawing displacement arrows
halfSpacing = (spacing * 0.5) - (arrowSize * 0.5);
# Compute final dimensions of the arrow head
wingSize = wingSizeFac * arrowSize;
headBase = wingSize * sind(angle);	# length of base of half arrow head
# Compute arrow offset from the base line
arrowOffset = offsetFac * width;
# get length of line in meters and set a check location 1 "spacing" distance
# before the line center (length * 0.5) to trigger drawing displacement
# arrows midway between adjacent triangles that are closest to the line center
lineCheck = (LineStyleGetDistanceTo(3) * 0.5) - halfSpacing;
############################### Draw ###########################
# Set line color and width
LineStyleSetColor(red, green, blue);
LineStyleSetLineWidth(width);
LineStyleSetCapJoinType(0,0);
cumDash = spacing - triWidth;			# intialize cumulative dash distance counter (for triangle placment)
# initialize flag indicating if arrow symbols have been drawn yet
arrowsDrawn = 0;
# special drawing instructions for LegendView
if (DrawingLegendView)
	{
	spacing = 0.5 * SampleRect.GetWidth();
	}
LineStyleRollPen(triWidth); # start line with dash
cumDash += triWidth;
# Draw triangles and arrows at specified spacing along line
while (LineStyleRoll(halfTri) != 1) 	# while not at end of line, roll half dash distance
	{
	dist = LineStyleGetDistanceTo(3);		# distance to end of line
	cumDash += halfTri;							# increment cumulative dash distance
	if (dist > triWidth && cumDash >= spacing) 	# draw triangle
		{
		LineStyleDropAnchor(1);			# anchor at left corner of triangle
		LineStyleRoll(halfTri);			# roll to midpoint of triangle base
		LineStyleMoveTo(0,0);			# move pen to current line position
		LineStyleMoveTo(90, height);	# move pen to top corner of triangle
		LineStyleDropAnchor(2);			# drop anchor at top corner
		LineStyleRoll(-halfTri);		# roll line pointer back along line to left corner
		LineStyleRecordPolygon();		# set up to record vertex positions for triangle polygon
		LineStyleRollPen(triWidth);	# draw complete base of triangle (to right corner)
		LineStyleLineToAnchor(2);		# line to top corner anchor
		LineStyleLineToAnchor(1);		# line from top to left corner anchor
		LineStyleDrawPolygon(1);		# fill the polygon
		cumDash = 0;						# reinitialize cumulative dash distance
		# draw displacement arrows when line position passes the check point
		# and set flag to indicate they have been drawn
		if (LineStyleGetPosition(1) > lineCheck && arrowsDrawn == 0)
			{
			LineStyleRoll(halfSpacing);	# move pointer along line halfway to next triangle;
													# pointer remains at this position while arrows are drawn
			# Draw first half-arrow forward on left side of line
			LineStyleMoveTo(90, arrowOffset);
			LineStyleDropAnchor(3);				# anchor at base of arrow shaft
			LineStyleMoveTo(0, arrowSize);	# move forward to tip of arrow
			LineStyleDropAnchor(4);				# anchor at tip of arrow
			LineStyleRecordPolygon(1);			# start recording vertices for arrow head polygon
			LineStyleLineTo(180 - angle, wingSize);	# draw arrowhead side
			LineStyleLineTo(-90, headBase);				# draw arrowhead base
			LineStyleDropAnchor(5);	
			LineStyleLineToAnchor(4);
			LineStyleDrawPolygon(1);				# fill polygon
			LineStyleMoveToAnchor(5);
			LineStyleLineToAnchor(3);				# draw arrow shaft back to base
			LineStyleMoveToAnchor(4);
			# Draw other half-arrow backward on right side of line
			LineStyleMoveTo(-90, 2 * arrowOffset);	# offset to other side of line
			LineStyleDropAnchor(6);					# anchor at base of arrow
			LineStyleMoveTo(180, arrowSize);		# move backward to tip of arrow
			LineStyleDropAnchor(7);					# anchor at tip of arrow
			LineStyleRecordPolygon(1);			# start recording vertices for arrow head polygon
			LineStyleLineTo(-angle, wingSize);
			LineStyleLineTo(90, headBase);
			LineStyleDropAnchor(8);
			LineStyleLineToAnchor(7);
			LineStyleDrawPolygon(1);
			LineStyleMoveToAnchor(8);
			LineStyleLineToAnchor(6);				# draw arrow shaft back to base
			LineStyleRoll(-halfSpacing);		# roll pointer back along line to end of previous
														# triangle for next triangle iteration to preserve spacing
			arrowsDrawn = 1;						# set flag to indicate arrows have been drawn
			}
		}
	else
		{
		LineStyleRollPen(triWidth);
		cumDash += triWidth;
		}
	}