PipelineTopographic.sml

  Download

More scripts: Raster

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# PipelineTopographic.sml
# Sample standalone script to demonstrate an image pipeline application
# using a single RVC source and a target consisting of several RVC raster objects.
# Script input: a DEM raster object in a Project File.
# Script output: RVC raster objects for Slope, Aspect, Shading, Profile Curvature,
# and Plan Curvature, computed using the SML classes equivalent to the Topographic
# Properties process in TNTmips.
# The FOCALTOPOGRAPHIC filter computes and creates output objects in the following order:
# Slope, Aspect, Shading, Profile Curvature, and Plan Curvature.  The FOCALTOPOGRAPHIC_SETTINGS
# class specifies which of these products should be computed and with what parameters.
# If the script computes more than one of these products, set up the pipeline target using an 
# ObjItemList (a hash of RVC_OBJITEMs returned by the DlgGetObjectSet() function).  Output objects 
# should be selected in the above order, and the number of objects prompted for must match the
# number of products the script tells the filter to produce. 
# 8 January 2008
# Revised 12 February 2008
# Randy Smith, MicroImages, Inc.
# Requires Version 2007:73 or later of the TNT products. 
numeric err;			# error number returned
# error checking procedure
proc ReportError(numeric linenum, numeric err) {
	printf("FAILED -line: %d, error: %d\n", linenum - 1, err);
	PopupError(err); 
	}
########################################  Main program  #########################################
clear();
# CHOOSE INPUT DEM
class RVC_RASTER DEM;				# the input Digital Elevation Model raster
GetInputRaster(DEM);
if (DEM.$Info.Type == "binary" or			# check for appropriate raster type
	DEM.$Info.Type == "16-bit color RGB" or
	DEM.$Info.Type == "16-bit color BGR" or
	DEM.$Info.Type == "24-bit color RGB" or
	DEM.$Info.Type == "24-bit color BGR") 
	{
	print("Binary or composite rasters cannot be used as input for this script.  Exiting now.");
	Exit();
	}
# Set processing parameters for topographic filter;
# In practice these settings could be read from a dialog window created by the script.
class IMAGE_PIPELINE_FILTER_FOCALTOPOGRAPHIC_SETTINGS settings;
settings.SetSurfaceFittingMethod("QLSF"); # use Quadratic least squares fit
settings.SetDoSlope(1);		# compute slope raster; 0 = don't compute
settings.SetSlopeDataType("FLOAT32");	# set slope raster to 32-bit floating point
settings.SetSlopeUnits("Degrees");	# compute slope in degrees rather than percent
settings.SetDoAspect(1);	# compute Aspect; 0 = don't compute
settings.SetAspectDataType("SINT16");	# set aspect raster to 16-bit signed integer
settings.SetDoShading(1);	# compute the shading raster; 0 = don't compute
settings.SetShadingDataType("UINT8");	# set shading raster to 8-bit unsigned integer
settings.SetShadingMethod("HighContrast");
settings.SetElevationAngleOfSun(60);	# sun elevation angle in degrees
settings.SetDirectionOfSun(300);		# set azimuth of direction to sun (clockwise from 0 at north)
settings.SetDoProfile(1);		# compute profile curvature
settings.SetDoPlan(1);		# compute plan curvature
settings.SetCurvatureDataType("FLOAT32");		# set curvature rasters to 32-bit floating point
settings.SetCurvatureUnits("RadiansPer100Meter");
# set labels for prompt dialog to select output objects;
# labels should be in the order shown, even if some are omitted.
class STRINGLIST labelList;	# list of labels for the selection dialog for the output objects
labelList.AddToEnd("Slope");
labelList.AddToEnd("Aspect");
labelList.AddToEnd("Shading");
labelList.AddToEnd("Profile");
labelList.AddToEnd("Plan");
# CHOOSE OUTPUT 
# Prompt for the output rasters using the labelList.
# DlgGetObjectSet populates a hash of ObjItems for the output; new rasters will then be created
# by the TARGET_RVC with the desired compression.  The ObjectPaths of the ObjItems are not
# valid until the output rasters are actually created by the pipeline.
class RVC_OBJITEM outObjItemList[];		# hash of object items for output
 
class STRING prompt$ = "Choose new raster objects for the output:";
err = DlgGetObjectSet(prompt$, "Raster", labelList, outObjItemList, "NewOnly,AllowAutoName");
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
# PIPELINE SOURCE
# set the input DEM as the pipeline source using its ObjItem
class IMAGE_PIPELINE_SOURCE_RVC source_DEM(DEM.GetObjItem() );
err = source_DEM.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else 
	print("Source DEM initialized.");
# PIPELINE FILTER
# set up the topographic properties filter
class IMAGE_PIPELINE_FILTER_FOCALTOPOGRAPHIC topoFilt(source_DEM, settings);
err = topoFilt.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Topographic filter initialized.");
# PIPELINE TARGET
# set output rasters as pipeline target using the ObjItem list returned by the DlgGetObjectSet function
class IMAGE_PIPELINE_TARGET_RVC target_rvc(topoFilt, outObjItemList);
target_rvc.SetCompression("DPCM", 0);
err = target_rvc.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Target initialized.");
# EXECUTE the pipeline process
print("Processing...");
target_rvc.Process();
print("Done.");