Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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)
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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