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 shipefileuser40752– user407522014年11月18日 14:46:04 +00:00Commented Nov 18, 2014 at 14:46
1 Answer 1
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– Ryan Spencer2013年02月26日 18:30:06 +00:00Commented 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
andPolyline_Name
fields, which should already exist in thetrackPolyLine
layer.dmahr– dmahr2013年02月26日 18:31:31 +00:00Commented 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!Ryan Spencer– Ryan Spencer2013年02月26日 18:35:20 +00:00Commented Feb 26, 2013 at 18:35