Created
September 9, 2015 23:45
-
-
Save nickpeihl/981b1269b4428fc5e4b1 to your computer and use it in GitHub Desktop.
Flip line directions with arcpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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