2

I am working with an empty feature class where I am writing a script to create polylines within the featureclass and attach an associated text value with the polyline.

I am using a for loop as noted below to insert the polyLine feature while updating a previously created field with the name of the polyline. Wonder if someone could provide some guidance as I cannot seem to get the name to write to table. The polyline creation works perfectly its just adding the name to the table that is providing some difficulty. The last bit code I know does not work.

for key in dictionary:
 cursor = arcpy.InsertCursor(trackPolyLine)
 feature = cursor.newRow()
 polyLine = arcpy.Polyline(dictionary[key], prjCode)
 feature.shape = polyLine
 cursor.insertRow(feature)
 name = arcpy.UpdateCursor(trackPolyLine)
 key.PolyLine_Name = key
 dictionary.updateRow(key)
Chad Cooper
12.8k4 gold badges48 silver badges87 bronze badges
asked Feb 26, 2013 at 17:58
1
  • how to get starting and ending coordonnates of polyline and update the database of this shipefile Commented Nov 18, 2014 at 14:46

1 Answer 1

4

I'm a little confused by your code. I think you can just use a single cursor to add the geometry and the name in one go--there's no need to use an insert cursor and an update cursor. Also, you should create your cursor outside of your for loop.

cursor = arcpy.InsertCursor(trackPolyLine)
for key in dictionary:
 feature = cursor.newRow()
 polyLine = arcpy.Polyline(dictionary[key], prjCode)
 feature.shape = polyLine
 feature.PolyLine_Name = key
 cursor.insertRow(feature)
answered Feb 26, 2013 at 18:12
3
  • so if I understand what you wrote, that would create a field for the geometry and a field for the name correct? Commented Feb 26, 2013 at 18:30
  • @RyanSpencer You can't create fields with cursors, but you can populate them. The code I provided populates the shape and Polyline_Name fields, which should already exist in the trackPolyLine layer. Commented Feb 26, 2013 at 18:31
  • Absolutely, been looking at the code for hours now and its starting to get to me haha! Thanks for the info as it ended up working! Commented Feb 26, 2013 at 18:35

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.