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)
  • how to get starting and ending coordonnates of polyline and update the database of this shipefile – user40752 Nov 18 '14 at 14:46
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)
  • so if I understand what you wrote, that would create a field for the geometry and a field for the name correct? – Ryan Spencer Feb 26 '13 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. – dmahr Feb 26 '13 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! – Ryan Spencer Feb 26 '13 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.