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


vecfocal.sml


# VecFocal.sml
#
# for each corresponding point in a vector layer - calculates focal mean around that
# same point in a corresponding raster layer
#
# a sample case would be extract maximum points from an elevation raster then use 
# the resulting vector points and the original raster
#
# a sample RVC project file called VecFocal.rvc has these two such files
#
#
# AUTHOR: 			David Wilson
# 						MicroImages, Inc.
# REQUESTED BY:
# CREATION DATE: 	Jan. 20, 1997
# REVISION LIST: 

#
# procedure and function definitions
#

#
# Global Variables
#
raster R;
vector V;

# set to true if you want to see output on console
numeric debugPrintToConsole = true;

# get the input raster and vector
GetInputRaster(R);
GetInputVector(V);

# get the desired output file name
string outFileName$ = PopupString("Input output file Name: ");

# open file for write
class FILE fHandle;
fHandle = fopen(outFileName$, "w");

clear(); # clear the console

# get georef object id's for raster and vector
class Georef georefR, georefV;
georefR = GetLastUsedGeorefObject(R);
georefV = GetLastUsedGeorefObject(V);

# determine number of points in vector
numeric numVectorPoints = NumVectorPoints(V);
array numeric focalOut[numVectorPoints];	# array to output for each point

# print to screen
if (debugPrintToConsole) {
	printf("%s\n\n", "Point   Vector X    Vector Y    georef X  " \
							+ " georef Y   Raster Row   Raster Col  Focal median");
	}

# print to file
fprintf(fHandle, "%s\n\n", "Point   Vector X    Vector Y    georef X  " \
							+ " georef Y   Raster Row   Raster Col  Focal median");

# loop over all points - compute mean in 5x5 area around each point
numeric i;
for i = 1 to numVectorPoints {

	# get the vector coordinates
	numeric x, y, xVector, yVector;
	x = V.point[i].Internal.x;
	y = V.point[i].Internal.y;

	# convert vector coordinates to georef
	ObjectToMap(V, x, y, georefV, xVector, yVector);

	# convert raster  coordinates to georef
	# note the reversal of rCol and rLine
	numeric rLine, rCol;
	MapToObject(georefR, xVector, yVector, R, rCol, rLine);

	# round rCol, rLine - could use floor() to force to upper left corner
	rLine = round(rLine);
	rCol = round(rCol);

	# calculate focal mean
	focalOut[i] = FocalMean(R, 5, 5, rLine, rCol);

	# print to screen
	if (debugPrintToConsole) {
		printf("%5d %10.2f  %10.2f  %10.2f  %10.2f  %10d   %10d %e\n", \
					 i, x, y, xVector, yVector, rLine, rCol, focalOut[i]);
		}

	# print to file
	fprintf(fHandle, "%5d %10.2f  %10.2f  %10.2f  %10.2f  %10d   %10d %e\n", \
					 i, x, y, xVector, yVector, rLine, rCol, focalOut[i]);

	}

GeorefFree(georefR);	# must free up id's
GeorefFree(georefV);

CloseRaster(R);	# close raster
fclose(fHandle);	# close text file


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