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


DEBUG.sml


# DEBUG.SML
# sample script for tutorial "Writing Scripts with SML"
# Version of VIEWSHED.SML showing use of $define, $ifdef, $endif
# preprocessor commands to define a DEBUG mode during script development.

# Computes binary viewshed raster from elevation Raster input
# use sample 8-bit input elevation raster CB_TM.RVC / ELEVATION
# use sample input vector object VIEWSHED.RVC / VROAD

# computes viewshed for all points on all lines
# of a corresponding Vector object
# could use to get viewshed for all points
# on one or more roads

### Declarations
array numeric xArray[10];	 # use to hold line points
array numeric yArray[10];

raster Rin, Rout;
vector V;

class GEOREF georefR, georefV; 
numeric numLines, numPoints;
numeric thisLine, numPointsInThisLine;
class MATRIX matX, matY;
numeric currentPoint, i;
numeric xVector, yVector, rCol, rLine;
numeric percent, height, zScale;

####
clear(); 	# clear the console
$define DEBUG

# get the input and output raster and Vector object
GetInputRaster( Rin );
GetInputVector( V );
GetOutputRaster( Rout, NumLins( Rin ), NumCols( Rin ), "binary" );

# get georef object id's for raster and vector
georefR = GetLastUsedGeorefObject( Rin );
georefV = GetLastUsedGeorefObject( V );

# first count total number of points in all lines
numLines = NumVectorLines( V );
numPoints = 0;

for thisLine = 1 to numLines {
	numPointsInThisLine = GetVectorLinePointList( V, xArray, yArray, thisLine );
	numPoints += numPointsInThisLine;

	$ifdef DEBUG
		printf( "Line= %d, NumVertices= %d\n", thisLine, numPointsInThisLine );
	$endif
	} 

# now create matrices large enough to hold points
matX = CreateMatrix(1, numPoints );
matY = CreateMatrix(1, numPoints );

# now loop through lines and fill in matrices with points

currentPoint = 0; 	# this will be our matrix index

for thisLine = 1 to numLines {
	numPointsInThisLine = GetVectorLinePointList( V, xArray, yArray, thisLine );

	for i = 1 to numPointsInThisLine {
		# convert vector coordinates to georef;
		ObjectToMap( V, xArray[i], yArray[i], georefV, 
					xVector, yVector );

		# convert vector coordinates to raster coordinates
		# note the order of rCol and rLine
		# col = x coord, row = y coord
		MapToObject( georefR, xVector, yVector, 
					Rin, rCol, rLine );

		# force to upper left corner
		rLine = floor( rLine ); 
		rCol = floor( rCol );

		# want matrix to index from zero to numPoints
		SetMatrixItem( matX, 0, currentPoint, rCol );
		SetMatrixItem( matY, 0, currentPoint, rLine );


		$ifdeg DEBUG
			printf( "i= %d, xVect= %.4f, yVect= %.4f, rLine= %d, rCol= %d\n", i, xVector, yVector, rLine, rCol );
		$endif
	

		currentPoint += 1;
		} # end of for i

	} # end of for each line in V

	# set default values - want any one point to make "visible"
	percent = 100 / numPoints;
	height = 2;
	zScale = 1;

	# now create the viewshed Raster object
	RasterToBinaryViewshed(  Rin, Rout, numPoints, matX, matY, percent, height, zScale );

	# clean up
	GeorefFree( georefR );	 # must free up id's
	GeorefFree( georefV );
	DestroyMatrix( matX );
	DestroyMatrix( matY );
	CloseRaster( Rin );
	CloseRaster( Rout );


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