Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# rtTransTen2c.qry
# This is a sample script for drawing a dashed line symbol for a
# right-lateral transtensional fault. Tick symbols are
# drawn on the downthrown (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 tick
# marks that are closest to the line center.
# 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 tickSizeMap, tickSize, tickSpaceMap, tickSpace, spacing, halfSpacing, dashSize, halfDash;
numeric arrowLengthMap, arrowSize, wingSizeFac, wingSize, angle, offsetFac, arrowOffset;
numeric 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;
# 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 controls the length of the tick marks.
# TickMap is the desired tick length in mm, assuming vector
# coordinates are in meters:
tickSizeMap = 2;
# This variable controls spacing between tick marks.
# SpaceMap is the desired spacing in mm, assuming vector
# coordinates are in meters. It should be several times larger
# than the arrowLengthMap set below.
tickSpaceMap = 15;
# This variable sets the number of dashes between tick marks
numDash = 3;
# 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
tickSize = 0.3 * SampleRect.GetHeight();
tickSpace = 0.6 * SampleRect.GetWidth();
width = 0.1 * SampleRect.GetHeight();
arrowSize = 0.35 * SampleRect.GetWidth();
}
else { # set dimensions for drawing elements in View using scale
scale = scale / 1000; # conversion from meters to millimeters
tickSize = tickSizeMap * scale;
tickSpace = tickSpaceMap * scale;
width = widthMap * scale;
arrowSize = arrowLengthMap * scale;
}
# Compute size of dashes from spacing and numDash
dashSize = tickSpace / (numDash * 1.5 + 1.5);
halfDash = dashSize * 0.5;
# Compute distance from end of last dash with tick mark to begining of next one
# (one dash length less than tick spacing)
spacing = tickSpace - dashSize;
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
# This variable controls how far from the base line to draw arrows
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 = 3 * (dashSize + halfDash); # intialize cumulative dash distance counter (for tick mark placment)
# initialize flag indicating if arrow symbols have been drawn yet
arrowsDrawn = 0;
# special drawing instructions for LegendView
if (DrawingLegendView)
{
lineCheck = 0.2 * SampleRect.GetWidth();
}
LineStyleRollPen(dashSize); # start line with dash
cumDash += dashSize;
# Draw tick marks and arrows at specified spacing along line
while (LineStyleRoll(halfDash) != 1) # while not at end of line, roll half dash distance
{
dist = LineStyleGetDistanceTo(3); # distance to end of line
cumDash += halfDash; # increment cumulative dash distance
if (dist > dashSize && cumDash >= spacing) # draw tick mark
{
LineStyleRollPen(halfDash);
LineStyleLineTo(90, tickSize);
LineStyleRollPen(halfDash);
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)
{
if (DrawingLegendView == 0) {
LineStyleRoll(halfSpacing); # move pointer along line halfway to next tick mark;
} # 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 previous
# tick mark for next iteration to preserve spacing
arrowsDrawn = 1; # set flag to indicate arrows have been drawn
}
}
else
{
LineStyleRollPen(dashSize);
cumDash += dashSize;
}
}