Skip to content

Instantly share code, notes, and snippets.

@nickpeihl
Created September 9, 2015 23:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpeihl/981b1269b4428fc5e4b1 to your computer and use it in GitHub Desktop.
Save nickpeihl/981b1269b4428fc5e4b1 to your computer and use it in GitHub Desktop.
Flip line directions with arcpy
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment