More scripts: Vector

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
# Sample script for tutorial Writing Scripts with SML
# Illustrates SML operations with vector objects.
# Designed for use with objects in the VectorData.rvc 
# Project File in the SML directory in the TNTmips
# sample data collection.
# Copies a section polygon from input Sections vector to a temporary vector
# to use as operator to extract lines for that section from the Streams
# input vector.  Extracted lines are written to second temporary vector
# which is then reprojected to WGS84 / Geographic Coordinate Reference System.
class RVC_VECTOR Sections;		# section polygons 1-36 for a township
class RVC_VECTOR Streams;		# stream lines with stream order for the township 
class RVC_VECTOR OutVec;		# output vector object
class RVC_VECTOR Temp1, Temp2;	# temporary vector objects for intermediate products
numeric err;
# select the two input vector objects
PopupMessage("Select the input vector object with section polygons.");
PopupMessage("Select the input vector object with stream lines.");
# select an output vector object
PopupMessage("Select a new vector object for the output.");
GetOutputVector(OutVec, "Planar");
# prompt user to choose the section number to extract streams lines
class STRING prompt$ = "Choose a section number between 1 and 36.";
numeric secnum = PopupNum(prompt$, 1, 1, 36, 0);
# convert the section number to a string and pad 0 in front of single-digit number.
# Use width value of "2" in sprintf() format string, preceded by 0 to pad width with 0.
class STRING section$ = sprintf("%02d", secnum);
### Use VectorCopyElements() function to extract the section polygon by query to a
### temporary vector object.
CreateTempVector(Temp1, "Polygonal");		# temporary vector to hold the extracted section
# set the query string to get the polygon for the selected section number
# (number is stored as a string in the polygon database table "Sections").
class STRING query$ = sprintf("Sections.SECTION == '%s'", section$);
printf("The query for selecting the section is: %s\n", query$);
# copy the desired section using the query for polygons (no points or lines)
err = VectorCopyElements(Sections, Temp1, "RemExRecords", "None", "None", query$);
if (err < 0) then
	print("Vector Copy Elements failed.");
	print("Vector Copy Elements succeeded.");
# prompt user for the minimum Strahler stream order value to extract
prompt$ = "Choose the minimum Strahler Stream Order value for the extracted stream lines.";
prompt$ = "1 = maximum detail, 3 = minimum detail";
numeric minorder = PopupNum(prompt$, 1, 1, 3, 0);
### Use VectorExtract() function with the Temp1 section vector as the operator to
### extract stream lines for the section area.  Use line query to get lines of the
### desired stream order
CreateTempVector(Temp2, "Planar");	# temporary vector to hold the extracted stream lines
# set the query string to extract and clip lines with stream order greater than or equal to
# the specified minimum stream order value
query$ = sprintf("STREAM_ORDER.Strahler >= %d", minorder);
printf("Query for selecting stream lines is: %s\n", query$);
Temp2 = VectorExtract(Temp1, Streams, "InsideClip", "RemExRecords", "None", query$, "None");
### Warp the extracted streams vector from the input CRS (NAD83 / UTM Zone 14N for default data)
### to WGS84 / Geographic CRS.
# get the georeference object from the Streams vector so we can get its CRS
class RVC_GEOREFERENCE streamGeoref;
# set up coordinate transformation with input and output CRS
class TRANS2D_MAPGEN trans;
trans.InputCoordRefSys = streamGeoref.GetCoordRefSys();
trans.OutputCoordRefSys = "Geographic2D_WGS84_Deg";
printf("Input CRS: %s\n", trans.InputCoordRefSys.Name);
printf("Output CRS: %s\n", trans.OutputCoordRefsys.Name);
err = VectorWarp(Temp2, OutVec, trans, 10);
if (err < 0) then
	print("Vector Warp failed.");
	print("Vector Warp succeeded.");