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


fragstat.sml

See other examples of Tool and Macro scripts ...


############################################################################
#  Fragstats.sml
#  Created by: Mark Smith
#  Most recent revision: 5-2001
#  This script takes an input raster and a mask raster, and uses the mask to
#  create a raster usable by fragstats.  It writes the output raster to a text
#  file and calls fragstats using a set of default parameters after querying
#  the user for the edge distance value.
#
#  The input raster must be an an integer-value, single raster with square cells.
#  Later versions may support more formats.  The mask raster must have exterior
#  background areas marked -1, interior background areas marked 1, and landscape
#  areas marked 0.
#
#  This script requires the fragstats executable which is installed in the TNT
#  mips win32 directory and that the temporary folder path specified by mips
#  have folder names no greater than 8 characters long or have spaces in them.

# Variable declarations
numeric lins, cols, csize, edist, value;
string type$, frag$, tempFile$, fragout$;
class File outFile;

# Setup rasters
raster Rin, Rmask;
GetInputRasters(Rin, Rmask);
IgnoreNull(Rin);
IgnoreNull(Rmask);
lins = NumLins(Rin);
cols = NumCols(Rin);
frag$ = GetInputFileName("c:/tnt/win32/fragstat.exe", "Please locate the fragstat executable.", "exe");
if (FileNameGetName(frag$)=="")
	goto cleanup;
tempFile$ = CreateTempFileName();
string realout$ = "";
fragout$ = GetToken(GetOutputFileName(_context.ScriptDir, "Where would you like the results?", ""), ".", 0);
numeric i;
for i = 1 to NumberTokens(fragout$, "\\") {
	string temp$ = GetToken(fragout$, "\\", i);
	if (strlen(temp$)>8 or NumberTokens(temp$, " ")>1) {
		realout$ = fragout$;
		fragout$ = FileNameGetPath(tempFile$)+FileNameGetName(tempFile$);
		break;
		}
	}
if (FileNameGetName(fragout$)=="")
	goto cleanup;
csize = (LinScale(Rin) + ColScale(Rin)) / 2;
edist = PopupNum("Enter the edge distance in meters:");


# Write to text file
outFile = fopen(tempFile$);

# Apply the mask for fragstats' use
value = 32071;
numeric row, column;
for row = 1 to lins step 1 {
	for column = 1 to cols step 1 {
		if (Rmask[row, column] == -1) then
			fprintf(outFile, "%d ", -value);
		if (Rmask[row, column] == 0) then
			fprintf(outFile, "%d ", Rin[row, column]);
		if (Rmask[row, column] == 1) then
			fprintf(outFile, "%d ", value);
		}
	if (row != lins)
		fprintf(outFile, "\n");
	}

# Close files
fclose(outFile);
CloseRaster(Rin);
CloseRaster(Rmask);

# Run fragstats
run(sprintf("%s %s %s %d %d 2 %d %d %d $ $ $ $ $ y y y y y", frag$, tempFile$, fragout$, csize, edist, lins, cols, value), 1);

if (realout$ != "") {
	CopyFile(fragout$+".cla", realout$+".cla");
	DeleteFile(fragout$+".cla");
	CopyFile(fragout$+".ful", realout$+".ful");
	DeleteFile(fragout$+".ful");
	CopyFile(fragout$+".lnd", realout$+".lnd");
	DeleteFile(fragout$+".lnd");
	CopyFile(fragout$+".pat", realout$+".pat");
	DeleteFile(fragout$+".pat");
	}

cleanup:
#Cleanup
#DeleteFile(Rout.$Info.Filename);
DeleteFile(tempFile$);


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