1

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
>>> 
asked Sep 17, 2019 at 13:28
14
  • What values does line_fields have in your code? Also, try line_in_cur.insertRow(row). No need to pass a tuple Commented Sep 17, 2019 at 13:39
  • Thanks @marcello-villa... I updated the code to show how I constructed my field list. I want to keep everything that's not automatically maintained/generated. If I modify insertRow(row), I get SystemError: error return without exception set. Commented Sep 17, 2019 at 14:26
  • 1
    It seems to me that the error is caused because you are passing a different number of values than the fields you are specifying in field_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 to insertRow()... that doesn't seem quite right. Regarding the geometry, the first way you are passing the geometry should work. Commented Sep 17, 2019 at 15:03
  • 1
    From your example of the new row you're inserting, you look to be inserting an arcpy.Array() object, which isn't a valid geometry. Wrap that in an arcpy.Polyline() Commented Sep 17, 2019 at 17:39
  • 1
    Yes, construct the Polyline but be sure to use the SpatialReference of the target feature class in the constructor, lest the coordinates be truncated to four places. Commented Sep 17, 2019 at 18:00

1 Answer 1

0

It's an ESRI bug with the da.insertCursor operating on features in a geometric network. NIM102778

answered Sep 20, 2019 at 17:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.