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


VIEWSHED.sml


# VIEWSHED.sml
# Computes binary viewshed raster from elevation raster input
# and vector object containing lines.

# Computes viewshed for all vertices 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 vertices
array numeric yArray[10];

class RASTER Rin, Rout;
class VECTOR V;

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

####
clear(); 	# clear the console

# 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 );
vecGeoToRastGeo.InputProjection = georefV.Projection;
vecGeoToRastGeo.OutputProjection = georefR.Projection;

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

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

# 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 object coordinates to map coordinates from its georef
		ObjectToMap( V, xArray[i], yArray[i], georefV, xVector, yVector );

		# convert vector map coordinates to map coordinates in raster's georef
		vecMapCoord.x = xVector;		# first assign map coordinates to a Point class
		vecMapCoord.y = yVector;		# required by TRANS2D_MAPGEN

		# do conversion using method on class TRANS2D_MAPGEN
		rastMapCoord = vecGeoToRastGeo.ConvertPoint2DFwd(vecMapCoord);

		# convert vector coordinates to raster coordinates
		# note the order of rCol and rLine
		# col = x coord, row = y coord
		MapToObject( georefR, rastMapCoord.x, rastMapCoord.y, 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 );
		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 );


$ifdef _MI_INTERNAL_AUTOTEST_MODE  # This is used for auto testing purposes only
	numeric checksum = 0;
	for each Rout {
		if (!IsNull(Rout)) checksum = checksum + Rout;
		}
	print("checksum:",checksum);
$endif

# 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