Building on Standalone Python script to split a polyline with a point layer, I don't think I am manipulating geometry objects correctly. I am splitting an original line, preserving all the attribution, and inserting new lines with the original attribution but updated geometry.
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = ["Primary OH Conductor", "Transformer Bank"]
line_lyr = layers[0]
point_lyr = layers[1]
points = [row[0] for row in arcpy.da.SearchCursor(point_lyr, "SHAPE@")]
line_fields = []
line_fields.append("SHAPE@")
try: arcpy.Delete_management("lines")
except: pass
arcpy.MakeFeatureLayer_management(line_lyr,"lines")
for rec in "lines":
with arcpy.da.SearchCursor(in_table = "lines",
field_names = line_fields) as o_search_cur:
feature_values = []
for row in o_search_cur:
feature_values.append(row)
line = row[-1]
for point in points:
if line.distanceTo(point) < 0.001:
snappoint = line.snapToLine(point).firstPoint
if not (snappoint.equals(line.lastPoint) and snappoint.equals(line.firstPoint)):
cutline1, cutline2 = line.cut(arcpy.Polyline(arcpy.Array([arcpy.Point(snappoint.X+10.0, snappoint.Y+10.0),
arcpy.Point(snappoint.X-10.0, snappoint.Y-10.0)]),
arcpy.SpatialReference(2276)))
a = feature_values[0][:-1] + tuple(cutline1)
row_values = [a]
with arcpy.da.InsertCursor(in_table = line_lyr,
field_names = line_fields) as line_in_cur:
for row in row_values:
print("inserting into column " + str(line_fields))
print("values: " + str(row))
print("original feature values (for reference): " + str(feature_values[0]))
line_in_cur.insertRow(row)
And my results:
inserting into column ['SHAPE@']
values: (<Array [<Point (2336683.24, 7228439.51939, #, #)>, <Point (2336751.76429, 7228385.5766, #, #)>]>,)
original feature values (for reference): (<Polyline object at 0x5b409c90[0x8a000660L]>,)
Runtime error
Traceback (most recent call last):
File "<string>", line 42, in <module>
TypeError: cannot read geometry sequence. expected list of floats
>>>
line_fieldshave in your code? Also, tryline_in_cur.insertRow(row). No need to pass a tuple – Marcelo Villa Sep 17 '19 at 13:39field_names, so I'd start by checking if the values you are passing have the same length as the list of fields. Also, it seems that you are passing a tuple with another tuple of values inside toinsertRow()... that doesn't seem quite right. Regarding the geometry, the first way you are passing the geometry should work. – Marcelo Villa Sep 17 '19 at 15:03line_fields[]and it shows up as the last item to be inserted for eachrowIn the OP, I included a sample from the original feature class (Polyline object) and a sample constructed forrow, the one that looks like an array. – mfrancis Sep 17 '19 at 15:05TypeError: cannot read geometry sequence. expected list of floatsMaybe I am getting closer? – mfrancis Sep 17 '19 at 15:58arcpy.Array()object, which isn't a valid geometry. Wrap that in anarcpy.Polyline()– mikewatt Sep 17 '19 at 17:39Polylinebut be sure to use theSpatialReferenceof the target feature class in the constructor, lest the coordinates be truncated to four places. – Vince Sep 17 '19 at 18:00a_geo = arcpy.Polyline(cutline1)that is when I get thecannot create geometry from inputserror. – mfrancis Sep 17 '19 at 20:58for rec in "lines":iterates through the string"lines". This merely repeats your code 5 times and should be removed. – Emil Brundage Sep 18 '19 at 22:56