VecLinesFromXYXYdB.sml

  Download

More scripts: Import & Export

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# Dave Breitwisch
# 23 March 2005
#
# Draw point-to-point lines to a new Vector object.  Coordinates taken
# from a main-level database.
#
#  Database will need one table with 4 fields in the following form:
#
#              StartX    StartY      EndX      EndY
#     
#    Line 1        X1        Y1        X2        Y2   
#    Line 2        X3        Y3        X4        Y4
#    Line 3        X5        Y5        X6        Y6 
#    ...
#    ...
#
#  Each line is symbolized as (X1, Y1) to (X2, Y2), etc,.. 
#  Each point is assumed to be in (Easting (m), Northing (m)).
#
#  Note:  Any overlaping lines that are created in the Vector will
#         have a node inserted at the intersection.
#
##################################################
# Change the following values to match your data #
##################################################
#
# filename$ = The location of the project file where the database is located
# objectname$ = Name of the database object holding your data
# tablename$ = Name of the table holding your data
#
string filename$ = "c:/Workspace/TestData.rvc";
string objectname$ = "Database";
string tablename$ = "SamplePts";
##################################################
# Declaration of variables                       #
##################################################
class DATABASE db;
class DBTABLEINFO tableInfo;
class GEOREF G;
numeric i;
array numeric line[4];
vector V;
##################################################
##################################################
clear();
# Select output Vector and Georeference
GetOutputVector(V, "VectorToolkit");
G = GeorefGetParms();
CopyGeorefToObject(V, G);
db = OpenDatabase(filename$, objectname$);
# Make sure the table containing the vector line points exists
# Print error and exit if it does not.
numeric n = TableExists(db, tablename$);
if (n == 0 ) {
  print("The table name specified in the script does not match your database");
  Exit();
}
# Determine number of entries
tableInfo = DatabaseGetTableInfo(db, tablename$);
numeric numberEntries = NumRecords(tableInfo);
# Read fields in each table entry and draw the line using the points
for i = 1 to numberEntries
{
  line[1] = TableReadFieldNum(tableInfo, "StartX", i);
  line[2] = TableReadFieldNum(tableInfo, "StartY", i);
  line[3] = TableReadFieldNum(tableInfo, "EndX", i);
  line[4] = TableReadFieldNum(tableInfo, "EndY", i);
  VectorAddTwoPointLine(V, line[1], line[2], line[3], line[4]);
}
# Clean up procedures
VectorValidate(V);
CloseDatabase(db);
CloseVector(V);
# Inform user of the number of lines that were drawn
print("Number of lines drawn to your output vector: ", numberEntries);