lftHiAngFlt2.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# lftHiAngFlt2.qry
# This is a sample script for drawing a leftt-lateral high-angle dip-slip 
# fault line (dashed) with U and D marking upthrown / downthrown sides of
# the fault.  The U symbol is drawn on the left side of the line.
# If this is the wrong side for an individual line, use
# the Spatial Data Editor to reverse its start and end points.
# Version Mar. 2008
# Requires TNTmips 2006:72 or later.
#
# Version 30 April 2008
# Fixes changes in line width and line end rendering caused by
# drawing text (internal error, but workaround is implemented).
# Improved drawing of displacement arrows so they look better for
# wider line widths.  Arrow offset determined from line width.
numeric red, green, blue;
numeric scale, lineLength, height, height8, heightMap;
numeric arrowLengthMap, arrowSize, wingSizeFac, wingSize, angle, offsetFac, arrowOffset;
numeric offset, width, widthMap, charWidth;
numeric dashMap, dashSize, halfDash;
numeric minangle, maxangle;
numeric shiftU, shiftD;
numeric lineCheck;
numeric udDrawn;		# flag to indicate whether displacement letters have been drawn yet
class RVC_GEOREFERENCE vGeoref;
class SR_COORDREFSYS vectCRS;
class STRING fontName$, 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;
# 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 dashes
# DashMap is the desired dash length in mm, assuming vector
# coordinates are in meters:
dashMap = 3;
# These variables control the drawing of the U and D
# text characters.  HeightMap is the desired height of the
# letters in mm, assuming vector coordinates are in meters.
heightMap = 5;
fontName$ = "ARIALBD.TTF";
# This variable controls the offset of the U and D text characters 
# on either side of the fault line.  It is the desired offset between 
# the line and the closest corner of the character.  Positioning of the 
# anchor point for each text label (lower left corner) is calculated from
# this offset factor, the local line orientation, and the character height.
offsetChar = 0.3;			# offset as a fraction of character height
# 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 
	height = 0.5 * SampleRect.GetHeight();
	width = 0.25 * height;
	dashSize = 0.3 * SampleRect.GetWidth();
	arrowSize = 0.4 * SampleRect.GetWidth();
	}
else {	# set dimensions for drawing elements in View
	scale = scale / 1000;	# conversion from meters to millimeters
	height = heightMap * scale;
	width = widthMap * scale;
	dashSize = dashMap * scale;
	arrowSize = arrowLengthMap * scale;
	}
halfDash = dashSize * 0.5;
# Compute additional parameters for letter placement
charWidth = height * 0.65;
height8 = 0.8 * height;
offset = height * offsetChar;
# 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 and set check location dashSize less than
# the midpoint; to be used to trigger placement of tick mark
lineCheck = (LineStyleGetDistanceTo(3) * 0.5) - dashSize;
############################ Draw ##############################
# Set line color, width, font and text color
LineStyleSetColor(red,green,blue);
LineStyleSetLineWidth(width);
LineStyleSetCapJoinType(0,0);
LineStyleSetFont(fontName$);
LineStyleSetTextColor(red, green, blue);
# initialize flag indicating if displacement letters have been drawn yet
udDrawn = 0;
LineStyleRollPen(dashSize); # start line with dash
while (LineStyleRoll(halfDash) != 1) { # while not at end of line roll length of half dash
	# draw U/D symbols when absolute position along line (in object units)
	# passes the check location near midpoint and set flag to indicate it has been drawn
	if (LineStyleGetPosition(1) > lineCheck && udDrawn == 0 )
		{ 
		LineStyleRoll(-arrowSize);			# roll back length of one arrow to draw U/D symbol
		LineStyleGetDirection(0, minangle, maxangle);		# get local line direction to determine U/D symbol placement
		# Determine shift of U / D symbols based on line direction
		if (minangle >= 0 and minangle < 90) {
			LineStyleMoveTo(180, 0.5 * (charWidth * cosd(minangle) + height8 * sind(minangle)));
			LineStyleDropAnchor(1);
			shiftU = offset + charWidth * sind(minangle);
			shiftD = offset + height8 * cosd(minangle);
			}
		else if (minangle >= 90 and minangle <= 180) 
			{
			LineStyleMoveTo(180, 0.5 * height8 * sind(180 - minangle));
			LineStyleMoveTo(0, 0.5 * charWidth * cosd(180 - minangle));
			LineStyleDropAnchor(1);
			shiftU = offset + charWidth * sind(minangle) - height8 * cosd(minangle);
			shiftD = offset;
			}
		else if (minangle > -180 and minangle < -90) 
			{
			LineStyleMoveTo(180, 0.5 * height8 * sind(180 - minangle));
			LineStyleMoveTo(0, 0.5 * charWidth * cosd(180 - minangle));
			LineStyleDropAnchor(1);
			shiftU = offset - height8 * cosd(minangle);
			shiftD = offset - charWidth * sind(minangle);
			}
		else if (minangle >= -90 and minangle < 0) 
			{
			LineStyleMoveTo(180, 0.5 * (charWidth * cosd(minangle) + height8 * sind(minangle)));
			LineStyleDropAnchor(1);
			shiftU = offset;
			shiftD = offset - charWidth * sind(minangle) + height8 * cosd(minangle);
			}
		# Draw U / D symbols
		LineStyleMoveTo(90, shiftU);
		LineStyleDrawText("U", height, 0, 1);
		LineStyleMoveToAnchor(1);
		LineStyleMoveTo(-90, shiftD);
		LineStyleDrawText("D", height, 0, 1);
		LineStyleSetLineWidth(width);
		LineStyleRoll(2 * arrowSize);		# roll forward to line center again
		# Draw first half-arrow backward on left side of line
		LineStyleMoveTo(90, arrowOffset);	# move to base of arrow
		LineStyleDropAnchor(3);					# anchor at base of arrow
		LineStyleMoveTo(180, arrowSize);		# move to tip of arrow
		LineStyleDropAnchor(4);					# anchor at tip of arrow
		LineStyleRecordPolygon(1);				# start recording vertices for arrow head polygon
		LineStyleLineTo(angle, wingSize);	# draw arrowhead side
		LineStyleLineTo(-90, headBase);		# draw arrowhead base
		LineStyleDropAnchor(5);					# anchor at base of arrow head on shaft
		LineStyleLineToAnchor(4);				# move to anchor at tip of arrow
		LineStyleDrawPolygon(1);				# fill polygon
		LineStyleMoveToAnchor(5);
		LineStyleLineToAnchor(3);				# draw arrow shaft back to base
		LineStyleMoveToAnchor(4);
		# Draw other half-arrow forward on right side of line
		LineStyleMoveTo(-90, 2 * arrowOffset);		# offset to other side of line
		LineStyleDropAnchor(6);							# anchor at base of arrow
		LineStyleMoveTo(0, arrowSize);				# move to tip of arrow
		LineStyleDropAnchor(7);							# anchor at tip of arrow
		LineStyleRecordPolygon(1);				# start recording vertices for arrow head polygon
		LineStyleLineTo(180 + angle, wingSize);
		LineStyleLineTo(90, headBase);
		LineStyleDropAnchor(8);
		LineStyleLineToAnchor(7);
		LineStyleDrawPolygon(1);				# fill polygon
		LineStyleMoveToAnchor(8);
		LineStyleLineToAnchor(6);				# draw arrow shaft back to base
		# Draw dashed line between arrows
		LineStyleRoll(-arrowSize);		# roll pointer back to center of line
		LineStyleRollPen(dashSize);	# draw dash
		udDrawn = 1;		# flag indicating letters have been drawn
		}
	else {
		LineStyleRollPen(dashSize);
		}
	}