gp = arcgisscripting.create(9.3) ... ... while sRow: pt = sRow.GetValue(shapeName).GetPart(0) ...
File "S:\scripts\test.py", line 91, in convertPointsToLine
pt = sRow.GetValue(shapeName).GetPart(0)
AttributeError: 'NoneType' object has no attribute 'GetPart'
Solved! Go to Solution.
val = row.getValue(shapeField) if val: pt = val.getPart(0) else: pt = None
shapeField = desc.shapeFieldName sRow = arcpy.SearchCursor(fc) for row in sRow: pt = row.getValue(shapeField).getPart(0)
import arcgisscripting
import os
import types
def convertPoints(inPts, outFeatures, IDField, cursorSort, close):
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 = "false"#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:
if 1 == 1:
# 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")
pt2 = 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 last point and this point are at identical locations
# nudge it about 1.5 meters to make a line
if pt2.X == pt.X and pt2.Y == pt.Y:
pt.Y = pt.Y + 0.00001
pt.X = pt.X + 0.00001gp = arcgisscripting.create()
Rewrite it using arcpy instead of arcgisscripting would be my suggestion. Have you tried creating the gp without forcing to 9.3?gp = arcgisscripting.create()
A while ago a post here by Esri stated it would still be available in 10.1, so not sure what the issue is as I haven't dabble in 10.1 myself yet.
http://forums.arcgis.com/threads/44713-Confirm-deprecation-of-arcgisscripting-at-10.1
val = row.getValue(shapeField) if val: pt = val.getPart(0) else: pt = None
Here is a useful blog post on updating arcgisscripting to arcpy: