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


Query_NN.sml


#********************************************************************
#The following code prints out a list of the nearest
#neighbor polygons after querying the user for a vector object
#and a polygon number:

# QRY_NN.SML
# Given a single polygon of a vector object,
# print out the nearest neighbor polygons.
# AUTHOR: Paul Pope, Environmental Monitoring Program, UW-Madison
# LAST MODIFIED: April 12, 1997

clear();

vector V;

# Prompt the user to enter the vector object
GetInputVector(V);

# Prompt the user to enter a polygon number of the vector object
numeric number_of_polygons = NumVectorPolys(V);
string prompt$ = "Enter the polygon ID number";
numeric polygon_ID_number = PopupNum(prompt$, 1, 1, number_of_polygons);

array numeric line_list[1];
array numeric nearest_neighbor_list[1];

numeric number_of_lines, number_of_neighbors;
number_of_lines = GetVectorPolyLineList(V,line_list, polygon_ID_number);
print("Number of Lines = ", number_of_lines);

number_of_neighbors = 0;

# Loop over the number of lines that make up the
# polygon and determine the nearest neighbor polygons
numeric j, k;
numeric leftpoly, rightpoly, outside_polygon, flag;
for j = 1 to number_of_lines step 1
{
	print("Line Number = ", line_list[j]);

	leftpoly = V.line[line_list[j]].Internal.LeftPoly;
	rightpoly = V.line[line_list[j]].Internal.RightPoly;

	print("Left Poly = ", leftpoly, "Right Poly = ", rightpoly);

	# A nearest neighbor polygon will be either
	# the leftpoly or the rightpoly to the line being evaluated
	if (leftpoly != polygon_ID_number) then
	{
		outside_polygon = leftpoly;
	}
	if (rightpoly != polygon_ID_number) then
	{
		outside_polygon = rightpoly;
	}

	# Ensure that this nearest neighbor has not
	# already been accounted for
	flag = 0;
	for k = 1 to number_of_neighbors step 1
	{
		if (nearest_neighbor_list[k] == outside_polygon) then
		{
			flag = 1;
		}
	}

	# If this nearest neighbor has not been
	# accounted for already, then add it to
	# the list of nearest neighbors
	if (flag != 1) then
	{

		# Make a copy of the nearest neighbor list
		if (number_of_neighbors > 0) then
		{
			array numeric temp_list[number_of_neighbors];
			for k = 1 to number_of_neighbors step 1
			{
				temp_list[k] = nearest_neighbor_list[k];
			}
		}

		# Redefine the number of elements in the list
		# of nearest neighbors and add the new nearest
		# neighbor to the end of the list
		number_of_neighbors = number_of_neighbors + 1;
		array numeric nearest_neighbor_list[number_of_neighbors];
		nearest_neighbor_list[number_of_neighbors] = outside_polygon;

		# Copy all of the previously determined nearest
		# neighbors into the newly expanded list
		if (number_of_neighbors > 1) then
		{
			for k = 1 to (number_of_neighbors - 1) step 1
			{
				nearest_neighbor_list[k] = temp_list[k];
			}
		}

		print("Nearest Neighbor = ", outside_polygon);

	}  # End of if-then statement

}  # End of looping over j, the number of lines

# Clear the console and print out the list
# of nearest neighbors
clear();
print("For Polygon ID number = ", polygon_ID_number,", ");
print("the number of nearest neighbors = ", number_of_neighbors);
for k = 1 to number_of_neighbors step 1
{
	print("Nearest Neighbor[", k, "] = ", nearest_neighbor_list[k]);
}

# End of SML script


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