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


VTOOLKIT.sml


# VTOOLKIT.SML
# sample script for tutorial "Writing Scripts with SML"
# illustrating use of vector toolkit.
# Use information from an input raster
# to add elements to a new vector object.

clear();

class RASTER R;
numeric xMin, yMin, xMax, yMax;
class GEOREF rGeoref;

# Get input raster and find its geographic extents in map
# coordinates defined by its last-used georeference object.
GetInputRaster(R);
rGeoref = GetLastUsedGeorefObject(R);
GetObjectExtents(R,xMin,yMin,xMax,yMax,rGeoref);

# Print raster georeference parameters to console.
printf("Raster coord system = %s\n", rGeoref.Projection.System);
printf("Zone = %s\n", rGeoref.Projection.Zone);
printf("Datum = %s\n\n", rGeoref.Projection.Datum);

# Get maximum raster value and find line,column
# position of maximum. (Stop search at first instance.)
numeric rmax, lin, col, maxline, maxcol, max_X, max_Y; 
rmax = GlobalMax(R);
for each R[lin,col] {
	if (R == rmax) {
		maxline = lin;
		maxcol = col;
		break;
	}
}

print("Maximum raster value = ",rmax);
print("Line number of maximum value =",maxline);
print("Column number of maximum value =",maxcol);

# Convert max cell location to map coordinates
ObjectToMap(R,maxcol,maxline,rGeoref,max_X,max_Y);

print("Map x coordinate of maximum =",max_X);
print("Map y coordinate of maximum =",max_Y);

# Get new output vector object and initialize it.
# for adding / modifying elements with the vector toolkit.
vector VecBoundary;
GetOutputVector(VecBoundary,"VectorToolkit,Polygonal");

# Create implied georeference for vector using georeference
# parameters from input raster.
class Georef vecGeoref;
CreateImpliedGeoref(VecBoundary, rGeoref.Projection);
vecGeoref = GetLastUsedGeorefObject(VecBoundary);

# Print resulting vector georeference parameters to console.
printf("VecBoundary coord system = %s\n", vecGeoref.Projection.System);
printf("Zone = %s\n", vecGeoref.Projection.Zone);
printf("Datum = %s\n\n", vecGeoref.Projection.Datum);

# Add point element to vector at location of maximum raster value.
VectorAddPoint(VecBoundary,max_X,max_Y);

# Create and fill arrays to hold vertex coordinates for
# vector boundary line.  Use extents values and begin at
# lower left extents corner and proceed clockwise,
# returning to beginning location to close boundary polygon.  

array numeric xPoints[5];
array numeric yPoints[5];

xPoints[1] = xMin;	yPoints[1] = yMin;
xPoints[2] = xMin;	yPoints[2] = yMax;
xPoints[3] = xMax;	yPoints[3] = yMax;
xPoints[4] = xMax;	yPoints[4] = yMin;
xPoints[5] = xMin;	yPoints[5] = yMin; # close polygon

# Add the vector line.
VectorAddLine(VecBoundary,5,xPoints,yPoints);

# Find the location on the new line that is closest to the 
# maximum raster point and draw a line between the two points.
numeric linenum, close_X, close_Y;
linenum = FindClosestLine(VecBoundary,max_X,max_Y,vecGeoref);
ClosestPointOnLine(VecBoundary,linenum,max_X,max_Y,close_X,close_Y);
VectorAddTwoPointLine(VecBoundary,max_X,max_Y,close_X,close_Y);

# Validate and close the vector object
VectorValidate(VecBoundary);
CloseVector(VecBoundary);

print("Process Completed.", "VecBoundary#Lines:", VecBoundary.$Info.NumLines);


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