I want to flip the direction of a polyline feature obtained as a result of an Update query; e.g.
lines= arcpy.UpdateCursor(myFeatureClass,myQuery)
dsc= arcpy.Describe(myFeatureClass)
try:
for ln in lines:
# ? Check number of parts
# ? Flip direction of each, or some of the parts
lines.updateRow(ln)
except:
print "Error:", sys.exc_info()[0]
finally:
# releasing locks
if lines: del lines
if ln: del ln
BTW, any better way to know how many rows are returned than counting them?
Answer
Just for the record, and to help the folks who might be looking:
def flipLine(myFeatureClass, myQuery):
try:
lines=arcpy.UpdateCursor(myFeatureClass, myQuery)
dsc=arcpy.Describe(myFeatureClass)
lc=0
for ln in lines:
if ln.shape.partCount > 1:
print "Warning: multiple parts! extra parts are automatically trimmed!"
lp= ln.shape.getPart(0)
rPnts=arcpy.Array()
for i in range(len(lp)): rPnts.append(lp[len(lp)-i-1])
rPoly=arcpy.Polyline(rPnts)
ln.shape= rPoly
lines.updateRow(ln)
except:
print "Error:", sys.exc_info()[0]
finally:
if lines: del lines
if ln: del ln
No comments:
Post a Comment