1

I have a feature class that is built using the calculated values along two lines. I am trying to add a new column with a value from each line but am not able to.

I have a list that looks like

['102382191', '102387203', 'fe3bd81d-4c9f-4134-b7fe-e3529d2d7749'],
['104750210', '104716195', 'fe886c2d-c0a4-42b5-9f5b-fcade3dda238']]

from this we get the three values

cursor = arcpy.da.InsertCursor(out_fd+"/Turn_Lines",
                           ["SHAPE@"])
for turn in turnNotAllowedList:
        fromUFI = turn[0]
        toUFI = turn[1]
        rUFI = turn [2]

We have an array which get us the positions along the line to use

streetDictA = {str(row[1]): row[0].positionAlongLine(0.5,True).firstPoint for row in arcpy.da.SearchCursor(
    out_fd+"/streets", ["SHAPE@","EdgeFID"])}

The feature to add is built using

array = arcpy.Array()
array.add(streetDictA[fromUFI])
array.add(streetDictB[toUFI])
#array.add(rUFI)
polyline = arcpy.Polyline(array,sr)
cursor.insertRow([polyline])

How do I get the table to include the rUFI value? so that it has enter image description here

I have tried cursor.insertRow([polyline],r_UFI) but I get

TypeError: insertRow() takes exactly 1 argument (2 given)

Do I need to insert the polyline and then separately add the new column and value like this?

an example line would have the following

>>> streetDictA[fromUFI]
<Point (150.7028015, -33.753457, #, #)>
>>> streetDictB[toUFI]
<Point (150.702866881, -33.7537085424, #, #)>
>>> rUFI
'00004e53-5700-4600-0000-0000245bdf33'
>>> 
BERA
  • 72,339
  • 13
  • 72
  • 161
GeorgeC
  • 8,228
  • 7
  • 52
  • 136

1 Answers1

2

With cursor = arcpy.da.InsertCursor(out_fd+"/Turn_Lines", ["SHAPE@"])

You already decided to only be able to insert one value: SHAPE@ then you try to insert two: [polyline] and r_UFI

You need to include both when creating the cursor:

import os
cursor = arcpy.da.InsertCursor(os.path.join(out_fd,"Turn_Lines"), ["SHAPE@","somefieldname"])

And the field "somefieldname" need to be added to your feature class before you can insert values.

BERA
  • 72,339
  • 13
  • 72
  • 161
  • Great -As this fc is built using the array, how do I add the r_UFI column to hold the value? – GeorgeC May 07 '20 at 05:52
  • Add Field: arcpy.AddField_management(in_table=os.path.join(out_fd,"Turn_Lines"),... – BERA May 07 '20 at 05:54
  • Sorry to be clear I have added the field as arcpy.AddField_management(in_table="Turn_Lines", field_name="r_UID", field_type="TEXT", field_precision="", field_scale="", field_length="50", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="") but how do I add the value r_UFI in the cursor.insertRow? – GeorgeC May 07 '20 at 06:03
  • 1
    Im not sure what you are doing with the shape, but something like cursor.insertRow([polyline,r_UFI]) should work. insertRow wants a "A list or tuple of values". Look at the examples in the help section – BERA May 07 '20 at 07:17