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


votdist.sml


## VOTDIST.SML 

## For vector object containing Voting Districts extracted from
## 1990 Census TIGER / Line files (which lack polygon attributes).  
## Checks line attributes in the Geo_Area_Codes table
## to find and verify voting district codes (string) for each polygon and
## writes the result into the polygon attribute table "Districts".
## The "Districts" Table must be set up previously
## with fields "PolyID" (integer) and "Voting_Dist" (string),
## with the Restriction option set to "Implied One-to-One"
## (which automatically creates a "blank" record for each polygon).

## Code verification involves determining the voting district code
## for the "inside" side of each line making up a polygon, then
## checking that all lines yield the same code for the polygon.
## (Codes are stored in an array for checking, which requires that
## the code character string be converted to a number first).
## Polygons whose lines yield inconsistent voting district codes
## are left unclassified, and an error statement is printed to the
## console window and to an error log file.  
 
## AUTHOR: Randy Smith, MicroImages, Inc.
## CREATION DATE: June 24, 1997
## REQUIRED TNTmips VERSION: 5.7 or later

clear();
vector V;
GetInputVector(V);
print ("Processing....");

class FILE errtext;
array numeric linelist[10];		# define array to contain list of line numbers for current polygon

errtext = fopen( "C:/temp/disterrs.txt", "a" );

numeric i, polyid;
numeric numlines, linenum;
numeric leftpoly, rightpoly;
numeric votingdistnum, allsame;
string votingdist$;
for each poly in V begin
	polyid = V.poly.Internal.ElemNum;		# assign current polygon number to variable

	# get list of lines making up current polygon and assign number of lines to variable
	numlines = GetVectorPolyLineList(V, linelist);

	array numeric distnums[numlines];		# define array to hold list of district numbers for polygon

		for i = 1 to numlines begin
			linenum = linelist[i];
			leftpoly = V.line[linenum].Internal.LeftPoly;			# get ID of polygon to left of line
			rightpoly = V.line[linenum].Internal.RightPoly; 	# get ID of polygon to right of line

			# check which side of line is the "inside" for the current polygon, and get the voting
			# district code from the appropriate string field (Voting_Dist_L or Voting_Dist_R) 
			# in the Geo_Area_Codes table. The field specification on right side of assignment
			# statement must have "$" at end to indicate that the database field should be
			# read as a string. 
			if ( leftpoly == polyid ) then
					votingdist$ = V.line[linenum].Geo_Area_Codes.Voting_Dist_L$;
			else
					votingdist$ = V.line[linenum].Geo_Area_Codes.Voting_Dist_R$;

			# convert voting district code to number for checking
			votingdistnum = StrToNum(votingdist$);

			# store voting district number for current line in array for checking
			distnums[i] = votingdistnum;
		end

		# loop to check that all district numbers in array are the same
		allsame = 1;			# error flag
		for i = 1 to numlines begin
			if ( distnums[1] != distnums[i] ) then
				begin
					allsame = 0;
					break;
				end
		end

		# if all voting district numbers are the same, 
		# write the PolyID, and Voting District code into the
		# respective fields in the polygon attribute table "Districts"
		if ( allsame == 1 ) then
			begin
				V.poly.Districts.PolyID = polyid;						# integer field
				V.poly.Districts.Voting_Dist$ = votingdist$;		# string field
			end
		else 
			begin
				printf("\nInconsistent voting district codes for polygon %d, not classified.", polyid );
				fprintf(errtext, "\nInconsistent voting district codes for polygon number %d, not classified ", polyid );
			end
end
fclose(errtext);
printf ("\nDone");


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