I figured it out by using the tool script that I found in ArcGIS 10.0 toolbox albeit I was working in 9.3.1.The code takes a point featureclass and converts it into lines and I modified it to work with reading a file. My actual task was to read a Zmap file in and convert it into line contours.Following is the ESRI code as found in the PointsToLines script tool:
#PointToLine.py script from ArcGIS 10.0 ArcCatalog Point to Line tool
import arcgisscripting
import os
import types
def convertPoints():
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = 1
# Input point FC
# Output FC
# Feature Field
# Sort Field
# Close Line or Leave Open
inPts = gp.GetParameterAsText(0)
outFeatures = gp.GetParameterAsText(1)
IDField = gp.GetParameterAsText(2)
sortField = gp.GetParameterAsText(3)
closeLine = gp.GetParameterAsText(4)
if IDField in ["", "#"]: IDField = None
if sortField in ["", "#"]:
cursorSort = IDField
else:
if IDField:
cursorSort = IDField + ";" + sortField
else:
cursorSort = sortField
if types.TypeType(closeLine) != types.BooleanType:
if closeLine.lower() == "false":
close = False
else:
close = True
convertPointsToLine(gp, inPts, outFeatures, IDField, cursorSort, close)
def enableParam(hasMZ):
if hasMZ:
return "ENABLED"
else:
return "DISABLED"
def convertPointsToLine(gp, inPts, outFeatures, IDField, cursorSort, close):
try:
# Assign empty values to cursor and row objects
iCur, sRow, sCur, feat = None, None, None, None
desc = gp.Describe(inPts)
shapeName = desc.ShapeFieldName
# Create the output feature class
#
outPath, outFC = os.path.split(outFeatures)
gp.CreateFeatureclass_management(outPath, outFC, "POLYLINE", "",
enableParam(desc.hasM),
enableParam(desc.hasZ),
inPts)
# If there is an IDField, add the equivalent to the output
#
if IDField:
f = gp.ListFields(inPts, IDField)[0]
tMap = {'Integer': 'LONG', 'String': 'TEXT', 'SmallInteger': 'SHORT'}
fType = f.type
if tMap.has_key(fType):
fType = tMap[fType]
fName = gp.ValidateFieldName(f.name, outPath)
gp.AddField_management(outFeatures, fName, fType, f.precision, f.scale, f.length,
f.aliasName, f.isNullable, f.required, f.domain)
# Open an insert cursor for the new feature class
#
iCur = gp.InsertCursor(outFeatures)
sCur = gp.SearchCursor(inPts, "", None, cursorSort, cursorSort)
sRow = sCur.Next()
# Create an array and point object needed to create features
#
array = gp.CreateObject("Array")
pt = gp.CreateObject("Point")
# Initialize a variable for keeping track of a feature's ID.
#
ID = -1
while sRow:
pt = sRow.GetValue(shapeName).GetPart(0)
if IDField:
currentValue = sRow.GetValue(IDField)
else:
currentValue = None
if ID == -1:
ID = currentValue
if ID <> currentValue:
if array.count >= 2:
# To close, add first point to the end
#
if close:
array.Add(array.GetObject(0))
feat = iCur.NewRow()
if IDField:
if ID: #in case the value is None/Null
feat.SetValue(IDField, ID)
feat.SetValue(shapeName, array)
iCur.InsertRow(feat)
else:
gp.AddIDMessage("WARNING", 1059, str(ID))
array.RemoveAll()
array.Add(pt)
ID = currentValue
sRow = sCur.Next()
# Add the last feature
#
if array.count > 1:
# To close, add first point to the end
#
if close:
array.Add(array.GetObject(0))
feat = iCur.NewRow()
if IDField:
if ID: #in case the value is None/Null
feat.SetValue(IDField, currentValue)
feat.SetValue(shapeName, array)
iCur.InsertRow(feat)
else:
gp.AddIDMessage("WARNING", 1059, str(ID))
array.RemoveAll()
except Exception as err:
gp.AddError(err.message)
finally:
if iCur:
del iCur
if sRow:
del sRow
if sCur:
del sCur
if feat:
del feat
if __name__ == '__main__':
convertPoints()