lineatn.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# lineatn.qry
# This is a sample script for drawing geologic point
# symbols for trend and plunge of mineral lineations (arrow).
# Information required for each point includes the trend
# azimuth (degrees) and plunge value (degrees).
# Each of these values is read from a particular
# field in an attached database table.  To use the script you
# will need to edit the statements that include database references
# to conform to your table name and field names.
# Trend angle must be specified as azimuth (0 to 360 degrees
# clockwise from north) of the down-plunge direction.
# Modified for drawing legend samples August 2002.
# Modified to declare all variables October 2005.
# Modified to correct for angle between grid north and true north May 2006.
# Version Dec. 2007
# Requires TNTmips 2007:73 or later.
# Modified to adjust scale based on georeference map units.
numeric azTrend, plunge1, scale;
numeric red, green, blue;
numeric arrowLengthMap, arrowLength, lineWidthMap, lineWidth;
numeric headSize, angle, stemLength;
numeric heightMap, height, halfHeight;
string fontName$;
numeric offset, direction, oppTrend, plunge1;
string label$;
numeric next_x ,next_y, labelLength;
numeric shift1, shift2;
class RVC_GEOREFERENCE vGeoref;
class SR_COORDREFSYS vectCRS;
numeric northAng;
class POINT2D point;
string coordUnit$;
###################### Set Parameters ##############################
# Read trend azimuth and plunge value from table.field
azTrend = Lineation.Trend;		###### change to fit your data
plunge1 = Lineation.Plunge;	###### change to fit your data
# 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;
# red, green, blue variables define the color of the symbols and label
red = 0;		green = 0;		blue = 0;
# These variables define the dimensions and line widths of the
# symbol.  ArrowLengthMap is the desired length of the symbol
# in mm, assuming vector coordinates are in meters.
# LineWidthMap is the desired line width in mm.
arrowLengthMap = 6;
lineWidthMap = 0.3;
# This variable controls the drawing of the label text string.
# HeightMap is the desired height of the letters in mm,
# assuming vector coordinates are in meters.
heightMap = 2.5;
# 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();
	lineWidth = 0.1 * arrowLength;
	height = 0.7 * SampleRect.GetHeight();
	}
else {	# set dimensions for drawing elements in view
	scale = scale / 1000;	# conversion from meters to millimeters
	arrowLength = arrowLengthMap * scale;
	lineWidth = lineWidthMap * scale;
	height = heightMap * scale;
	}
# This variable controls the length of the arrow head
headSize = 0.3 * arrowLength;
# This variable controls the sweep angle of the arrow in degrees
angle = 40; 			# 40 degree angle
# This variable sets the length of the lines redrawn over the
# arrow stems
stemLength = arrowLength - headSize * cosd(angle);
halfHeight = 0.5 * height;
fontName$ = "ARIALBD.TTF";
offset = arrowLength * 0.1; 		# offset of label from symbol
######################## Process ###########################
# find angle to north at the current point's map coordinates 
class TRANS2D_MAPGEN transObjToMap;
class TRANSMODEL model;
model = vGeoref.GetCalibModel();
vGeoref.GetTransParm(transObjToMap, 0, model);
point.x = Vect.Point.Internal.x;		# object coordinates of current point
point.y = Vect.Point.Internal.y;
point = transObjToMap.ConvertPoint2DFwd(point);		# convert to map coordinates
northAng = vectCRS.ComputeAngleToNorth(point);
# subtract the angle to north from the stored trend value
azTrend = azTrend - northAng;
# Convert trend azimuth to internal coordinate system.
direction = -(azTrend - 90);
if (direction < 0)
	direction = direction + 360;
oppTrend = direction - 180;
# Convert plunge value to a string and assign it to a
# string variable for use as label
label$ = sprintf("%2d", plunge1);
# Find length of label text for label positioning
LineStyleTextNextPosition(label$, height, 0, 1, next_x ,next_y, labelLength);
# Set line color, width, and end type
LineStyleSetColor(red, green, blue);		# set symbol color
LineStyleSetLineWidth(lineWidth);
LineStyleSetCapJoinType(1,1); 	# square ends of lines
# Draw arrow with zero line width, tip of stem at data point
# but centered on point if legend sample
if (DrawingSample == 1) {
	LineStyleMoveTo(oppTrend, arrowLength / 2);
	LineStyleMoveTo(-90,5);
}
LineStyleDropAnchor(0);				# anchor at data point
LineStyleSetLineWidth(0);
LineStyleDrawArrow(direction, arrowLength, headSize, angle, 1);
LineStyleDropAnchor(1);				# anchor at tip of arrow
# Draw arrow stem with desired line width
LineStyleMoveToAnchor(0);
LineStyleSetLineWidth(lineWidth);
LineStyleLineTo(direction, stemLength);
LineStyleMoveToAnchor(1);
########## Add plunge label
# Set font name and text color
LineStyleSetFont(fontName$);
LineStyleSetTextColor(red, green, blue);
# Compute label shift perpendicular to trend to center label
	shift1 = 0.5 * ( height * cosd(direction) - labelLength * sind(direction) );
# Compute label shift in trend direction to avoid overwriting symbol
if (direction >= 0 and direction < 90) then
	shift2 = offset;
else if (direction >= 90 and direction < 180) then
	shift2 = offset - 0.8 * labelLength * cosd(direction);
else if (direction >= 180 and direction < 270) then
	shift2 = offset - 0.8 * ( labelLength * cosd(direction) + height * sind(direction));
else if (direction >= 270 and direction <= 360) then
	shift2 = offset - 0.8 * height * sind(direction);
# Shift pen position and draw label
if (shift1 <0) {
	shift1 = abs(shift1);
	LineStyleMoveTo(direction + 90, shift1);
	}
	else {
	LineStyleMoveTo(direction - 90, shift1); }
LineStyleMoveTo(direction, shift2);
LineStyleDrawText(label$, height, 0, 1);