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
>>>
mfrancismfrancis
asked Sep 17, 2019 at 13:28
1 Answer 1
It's an ESRI bug with the da.insertCursor operating on features in a geometric network. NIM102778
answered Sep 20, 2019 at 17:51
lang-py
line_fields
have in your code? Also, tryline_in_cur.insertRow(row)
. No need to pass a tuplefield_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.arcpy.Array()
object, which isn't a valid geometry. Wrap that in anarcpy.Polyline()
Polyline
but be sure to use theSpatialReference
of the target feature class in the constructor, lest the coordinates be truncated to four places.