Splitting lines at vertices in ArcGIS Desktop with Basic level license?
I've put together some code below which seems to create single segment lines from polyline (which can be multipart) feature classes while retaining their attributes.
I recommend that you run it against a small test dataset or two first, and if it seems to do what you want, then comment out or remove the print statements to gain some performance.
If you add this to a Python script tool then you should be able to use it in a model at either ArcGIS 10.1 or 10.2. Earlier versions will not be able to use it because I have included arcpy.da for performance.
import arcpy
inFC = r"C:\temp\testLines.shp"
outFC = r"C:\temp\testLinesSplit.shp"
if arcpy.Exists(outFC):
arcpy.Delete_management(outFC)
arcpy.CreateFeatureclass_management("C:/temp","testLinesSplit.shp","POLYLINE","#","DISABLED","DISABLED",inFC)
arcpy.AddField_management(outFC,"inFID","LONG","#","#","#","#","NULLABLE","NON_REQUIRED","#")
iCursor = arcpy.da.InsertCursor(outFC, ["inFID","SHAPE@"])
with arcpy.da.SearchCursor(inFC,["OID@", "SHAPE@"]) as sCursor:
for row in sCursor:
inFID = row[0]
# Print the current multipoint's ID
#
print("Feature {0}:".format(row[0]))
partnum = 0
# Step through each part of the feature
#
for part in row[1]:
# Print the part number
#
print("Part {0}:".format(partnum))
# Step through each vertex in the feature
#
prevX = None
prevY = None
for pnt in part:
if pnt:
# Print x,y coordinates of current point
#
print("{0}, {1}".format(pnt.X, pnt.Y))
if prevX:
array = arcpy.Array([arcpy.Point(prevX, prevY),
arcpy.Point(pnt.X, pnt.Y)])
polyline = arcpy.Polyline(array)
iCursor.insertRow([inFID,polyline])
prevX = pnt.X
prevY = pnt.Y
else:
# If pnt is None, this represents an interior ring
#
print("Interior Ring:")
partnum += 1
del iCursor
arcpy.JoinField_management(outFC,"inFID",inFC,"FID","#")
There are a couple of solutions open to you, which spring to mind. The simplest is to use ET-GeoTools and select the 'Split in all Vertices' tool. Another option would be to script a process to iterate over the vertices of each line and assemble a new feature class from the bits.
I want to add that if you've got numpy installed it is way easier to transform the vertices of a multiline Feature into vertices..
You Need to create Numpy Array first out of your line Feature class (with arcpy's FeatureClassToNumPyArray), then you use the function 'explode to points=True'. And finally you just write the numpy Array back to a Feature class (NumPyArrayToFeatureClass). sr stands for 'spatial reference', which you Need to define
import arcpy
import numpy as np
InFcVF = r"input.shp" # input feature class
OutFcVF = r"output.shp" # output feature class
print "Daten gelesen.."
# Creates NumPy array from Input Feature
array = arcpy.da.FeatureClassToNumPyArray(InFcVF,["SHAPE@XY"], "", sr, explode_to_points=True)
print "Numpy Array created.."
# if Feature as Array wasnt created
if array.size == 0:
arcpy.AddError(InFcVF + " contains no feature.")
# Multipoint Feature from arra
else:
print "Aus Numpy Array wurde ein neues Multipoint Feature (VF) erstellt.."
arcpy.da.NumPyArrayToFeatureClass(array, OutFcVF, ['SHAPE@XY'], sr)
print "Numpy Array created.."`