home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


SlopeAspectDataTip.sml

 

See other examples and scripts with DataTips and GraphTips ...


### SlopeAspectDataTip.sml

### Sample Display Control Script that creates an Enhanced DataTip
### for a group that includes an elevation raster (DEM) as the first layer, 
### with any type or number of other layers.  Script computes slope and
### aspect for the DEM cell under the cursor and reports them in the DataTip
### under a centered heading indicating that they are computed values.

### Formatting codes enclosed in { } are embedded in the DataTip string
### to set justification, change fonts, and set tab stops.

### Add script to group or layout using Group / Edit Control Script or
### Layout / Edit Control Script.

### Requires TNTmips v7.0

### Randy Smith, MicroImages, Inc.
### version 19 August 2004. 

## variables for DEM raster
class GRE_LAYER_RASTER DEM_layer;
class RASTER DEM;
class TRANSPARM trans;
class POINT2D ptLayer;
class COLOR bgColor;

numeric lin, col;		# line and column position
numeric w, h;			# cell size (width and height)
numeric nullDEM;		# null value for DEM
numeric dzX, dzY;		# derivatives of Z in X and Y directions
numeric slope, aspect;
string slope$, aspect$;
string slopeFmt$, aspectFmt$;

### procedure called when View is created for Group;
### use to get GRE_GROUP class instance so script
### can access the first layer and assign the DEM to
### a raster variable
proc OnGroupCreateView (
   class GRE_GROUP group				## predefined class variable
   ) {
   DEM_layer = group.FirstLayer;
	DispGetRasterFromLayer(DEM, DEM_layer);
	w = ColScale(DEM);
	h = LinScale(DEM);
	nullDEM = NullValue(DEM);
   }

### procedure called when the DataTip event is triggered
func OnViewDataTipShowText (
   class GRE_VIEW view,					## predefined class variables
   class POINT2D point,
   class TOOLTIP datatip				## predefined variable for the DataTip
   ) {
   numeric retval = 1;		### when returned by the procedure, this value suppresses
									### "standard" DataTip text and uses only that created by script

	## define background color and assign it to the DataTip;
	## set margins for the enhanced DataTip
	bgColor.Red = 78; bgColor.Green = 94; bgColor.Blue = 100;
	datatip.BackgroundColor = bgColor;
	datatip.MarginHeight = 4;
	datatip.MarginWidth = 4;

	## create centered heading in red for enhanced DataTip
   datatip.String = "{~CJ~TS12~C100,0,0~FARIALBD.TTF}Computed from DEM:{~LJ~TS13~C0,0,0}\n";

	## get transformation from screen to layer coordinates for DEM layer
	trans = view.GetTransLayerToScreen(DEM_layer, 1);
	ptLayer = trans.ConvertPoint2DFwd(point);		## cursor position in layer object coordinates

	lin = floor(ptLayer.y);		## integer line and column position of DEM cell under cursor
	col = floor(ptLayer.x);

	if ( DEM[lin,col] <> nullDEM ) {		## if cursor is not over a null cell, proceed

		## compute x and y derivatives and slope
		dzX = ( DEM[lin, col + 1] - DEM[lin, col - 1] ) / (2 * w);
		dzY = ( DEM[lin - 1, col] - DEM[lin + 1, col] ) / (2 * h);

		slope = atand( sqrt( sqr(dzX) + sqr(dzY) ) );

		slope$ = sprintf("%.1f degrees", slope);	 ## text string from slope

		## create tabbed and formatted string for slope (2nd) line in DataTip 
		slopeFmt$ = sprintf("{~TABS 6L, 18R}Slope \t{~FARIAL.TTF}= \t%s\n", slope$); 


		## compute aspect
		if (slope == 0) {			
			aspect$ = "Undefined";		## aspect is undefined for flat areas
			}

		else {

			if (dzY != 0)	{		## check for division by zero
				aspect = deg * atan2(-dzX, -dzY);

				if (aspect < 0 ) then
					aspect += 360;
				}

			else
				aspect = 90;	## when dzY = 0

			aspect$ = sprintf("%.1f degrees", aspect);	## aspect text string
			}

		## create tabbed and formatted string for aspect (3rd) line in DataTip
		aspectFmt$ = sprintf("{~TABS 6L, 18R}{~FARIALBD.TTF}Aspect \t{~FARIAL.TTF}= \t%s\n", aspect$);

		## concatenate strings to create final Enhanced DataTip string
		datatip.String = datatip.String + slopeFmt$ + aspectFmt$;

		}

	else
		retval = -1;		## when returned by procedure, this value completely suppresses the DataTip
								## in this case when cursor is over null cell (or outside DEM raster)
	return (retval);
   }


Back Home ©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010   USA
Business & Sales: (402)477-9554  Support: (402)477-9562  Fax: (402)477-9559
Business info@microimages.com  Support support@microimages.com  Web webmaster@microimages.com

25 March 2009

page update: 26 May 11