Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# Create city boundary vector object from tiger data
# INPUT: tiger data (multiple objects)
# OUTPUT: city boundary vector
clear();
class RVC_VECTOR Output;
class DATABASE db;
class DBTABLEINFO tinfo;
string fieldname$;
class DATABASE linedb;
class DBTABLEVAR linevar;
class DBTABLEINFO linetable;
numeric numInputs = GetInputVectorList(InputList,"Input Tigers");
if (numInputs <= 0) return;
GetOutputVector(Output,"VectorToolkit,Polygonal");
CopySubobjects(InputList[1],Output,"GEOREF");
#VectorToolkitInit(Output);
array numeric xarray[1];
array numeric yarray[1];
numeric numpolys;
numpolys = 1;
array numeric records[1];
numeric numberofthem;
fieldname$ = "City_Names";
db = OpenVectorPolyDatabase(Output);
tinfo = TableCreate(db, "CITY_NAMES", "Created by SML script");
tinfo.OneRecordPerElement = 1;
TableAddFieldString(Output.poly.CITY_NAMES, fieldname$, 40);
string string$;
numeric i, j, numLines, numPoints;
numeric recordnumber, numberofthem;
numeric left, right;
for i = 1 to numInputs {
SetStatusMessage(sprintf("Processing vector %d of %d\n",i,numInputs));
linedb = OpenVectorLineDatabase(InputList[i]);
if (TableExists(linedb, "Geo_Names_P") > 0) {
linevar = TableOpen(linedb,"Geo_Names_P");
linetable = TableGetInfo(linevar);
numLines = NumVectorLines(InputList[i]);
for j = 1 to numLines {
SetStatusBar(j,numLines);
left = (InputList[i].line[j].Basic_Data.FIPS_Pub55Pla_L);
right = (InputList[i].line[j].Basic_Data.FIPS_Pub55Pla_R);
if (left != right) {
numPoints = GetVectorLinePointList(InputList[i],xarray,yarray,j);
VectorAddLine(Output,numPoints,xarray,yarray);
}
if (NumVectorPolys(Output) >= numpolys) {
numberofthem = TableReadAttachment(linetable,j,records);
string$ = TableReadFieldStr(linetable,"Geographic_Name",records[1]);
if ((string$ == "") && (numberofthem > 1)) #hack for bad data in nebraska otoe county should fix it
string$ = TableReadFieldStr(linetable,"Geographic_Name",records[2]);
recordnumber = TableNewRecord(tinfo,string$);
records[1] = recordnumber;
numberofthem = TableWriteAttachment(tinfo,numpolys,records,1);
numpolys = numpolys + 1;
}
}
}
}
array numeric islands[1];
numeric size;
size = 100;
array numeric deleteisland[size];
numeric numofislands;
numeric k;
k = 1;
for each poly[i] in Output {
numofislands = GetVectorPolyIslandList(Output,islands);
if (numofislands > 0) {
for j = 1 to numofislands {
TableReadAttachment(tinfo,islands[j],records);
RecordDelete(tinfo,records[1]);
deleteisland[k] = islands[j];
k += 1;
if (k >= size) {
ResizeArrayPreserve(deleteisland,size+100);
size += 100;
}
}
}
}
if (k > 1)
VectorDeletePolys(Output,deleteisland,k-1);
print("The number of island polygons deleted was",k-1);
SetStatusBar(0,10);
VectorValidate(Output); #this probably should be done