arrow.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# arrow.qry
# This is a sample script for drawing an unfilled arrow symbol
# indicating the direction and rate of plate motion on a 
# geotectonic map.  The arrow points in the direction of motion
# and a text label shows the associated rate.  Direction and rate
# values are obtained for each point from specific fields in an
# attached database.  To use the script you will need to edit
# the field and table names to correctly reference your
# attribute data.
# Modified to provide scaling for LegendView samples, August 2002;
# Modified to declare all variables, October 2005;
# Version Dec. 2007
# Requires TNTmips 2007:73 or later.
# Modified to adjust scale based on georeference map units
numeric red, green, blue, scale;
numeric azAngle, rate1, arrowLengthMap, arrowLength, widthMap, width;
numeric heightMap, height, baseSize, stemLength, sweepAngle, offset;
numeric direction, perpDirect, next_x ,next_y, labelLength;
numeric headLength, headSize, arrowWingSize, shift;
string fontname$, label$;
class RVC_GEOREFERENCE vGeoref;
class SR_COORDREFSYS vectCRS;
###################### Set Parameters ##############################
# Read azimuth and rate of motion vector from table.field
azAngle = PlateMotion.Azimuth			###### change to fit your data
rate1 = PlateMotion.Rate				###### change to fit your data
# red, green, blue variables define the color of the lines
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.
# Example: for 1:24,000 map scale, Scale = 24000
scale = 24000;
# This variable defines the dimensions of the arrow symbol
# ArrowLengthMap is the desired overall arrow length in mm,
# assuming vector coordinates are in meters.
arrowLengthMap = 10;
# These variables control the width of the lines.
# WidthMap is the desired map width in mm, assuming vector
# coordinates are in meters.
widthMap = 0.3
# These variables control the drawing of the label
# text string.  HeightMap is the desired height of the
# letters in mm, assuming vector coordinates are in meters.
heightMap = 3
# 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
	arrowLength = 0.5 * SampleRect.GetWidth();
	width = 0.1 * SampleRect.GetHeight();
	height = 0.3 * SampleRect.GetHeight();
	}
else {
	scale = scale / 1000;
	arrowLength = arrowLengthMap * scale;
	width = widthMap * scale;
	height = heightMap * scale;
	}
offset = 0.2 * arrowLength;		# offset of label from base of arrow
baseSize = arrowLength / 10;					# half width of base
stemLength = arrowLength * 0.67;				# length of arrow stem
sweepAngle = 30; 		# sweep angle of arrow wings in degrees
headLength = arrowLength - stemLength;
headSide = headLength / cosd(sweepAngle)
arrowWingSize = headLength * tand(sweepAngle) - baseSize;
fontname$ = "ARIALBD.TTF";
######################## Process ###########################
# Convert motion vector azimuth to internal coordinates.
direction = -(azAngle - 90);
if (direction < 0)
	direction = direction + 360;
perpDirect = direction + 90;
# Convert motion rate value to a string and assign it to a
# string variable for use as label
LineStyleSetFont(fontname$);
LineStyleSetTextColor(red, green, blue);
label$ = sprintf("%.1f", rate1);
# Find length of label text for label positioning
LineStyleTextNextPosition(label$, height, 0, 1, next_x ,next_y, labelLength);
# Compute final parameters and draw arrow
LineStyleSetColor(red, green, blue);
LineStyleSetLineWidth(width);
LineStyleDropAnchor(1);
LineStyleLineTo(perpDirect, baseSize);
LineStyleLineTo(direction, stemLength);
LineStyleLineTo(perpDirect, arrowWingSize)
LineStyleLineTo(direction - sweepAngle, headSide)
LineStyleLineTo(direction - 180 + sweepAngle, headSide)
LineStyleLineTo(perpDirect, arrowWingSize)
LineStyleLineTo(direction + 180, stemLength)
LineStyleLineToAnchor(1);
# Place rate of motion label at base of arrow
if (direction >= 0 and direction < 90)
	shift = offset + labelLength * cosd(direction) + height * sind(direction);
if (direction >= 90 and direction < 180)
	shift = offset + height * sind(direction);
if (direction >= 180 and direction < 270)
	shift = offset;
if (direction >= 270 and direction <= 360)
	shift = offset + labelLength * cosd(direction);
LineStyleMoveTo(direction - 180, shift);
LineStyleDrawText(label$, height, 0, 1);