The code:
##split line at point script ##Emil Brundage ##emilharold@gmail.com ### USER INPUTS #input feature class inFc = r"C:\Path\To\Data.gdb\InPolylines" #output feature class #will be created by script outFc = r"C:\Path\To\Data.gdb\OutPolylines" ### END USER INPUTS #---------- print "importing" import arcpy import os print "creating new feature class" outPath, outName = os.path.split (outFc) outFc = arcpy.CreateUniqueName (outName, outPath) outPath, outName = os.path.split (outFc) outFc = arcpy.CreateFeatureclass_management (outPath, outName, "POLYLINE", inFc, spatial_reference = inFc) [0] print "determining fields" flds = [f.name for f in arcpy.ListFields (inFc)] flds = [f.name for f in arcpy.ListFields (outFc) if f.name in flds] + ["SHAPE@"] print "iterating" with arcpy.da.InsertCursor (outFc, flds) as iCurs: with arcpy.da.SearchCursor (inFc, flds) as sCurs: for row in sCurs: row = list (row) geom = row [-1] if not geom: iCurs.insertRow (row) continue for i in range (geom.partCount): part = geom.getPart (i) fPoint = None count = part.count for c in range (count): if fPoint == None: fPoint = part.getObject (c) continue lPoint = part.getObject (c) ln = arcpy.Polyline (arcpy.Array ([fPoint, lPoint])) row [-1] = ln iCurs.insertRow (row) fPoint = lPoint print print "created:" print outFc print print "done"
No comments:
Post a Comment