cursor - Add shp attribute data to column with python -


if feature column in table ferry crossing need add yes ferry column have added table. if feature column not ferry crossing need add no ferry column. here chunk of code having issue with. suggestions? yes i'm new python, advice or hints appreciated me learn. cheers.

#need update ferry column yes or no values if ferry crossing available in feature field delimfield = arcpy.addfielddelimiters(fc, "ferry") cursor = arcpy.da.updatecursor(fc, ["ferry"]) row in cursor:     if row[0] == "ferry crossing":         cursor.updaterow("ferry")         print "yes"     if row[0] not "ferry crossing":         cursor.updaterow("ferry")         print "no"  del row del cursor  #if feature ferry crossing == yes in ferry field #if feature not ferry crossing == no in ferry field 

you need grab both fields in cursor: feature field test , ferry field want update. then, existing code test, you'll need modify perform update. use list positions of fields access them in row object.

with arcpy.da.updatecursor(fc, ["feature", "ferry"]) cursor:     row in cursor:         if row[0] == "ferry crossing": # test feature field             row[1] = "ferry" # set ferry field             print "yes"         else:             print "no"         cursor.updaterow(row) # commit changes 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -