I need to change values in field "name1" (string field) in specific rows: 70-72 into "no land use" value. I search Arcpy code to do it.
i red How to select specific row in attribute table using ArcPy (without iterating through whole table)? but didn't understand what shoud i do.
I using this code:
import arcpy
lyrName = r"G:\PROJECTS\herzel138\gis\layers\New File Geodatabase.gdb\digum2"
with arcpy.da.UpdateCursor(lyrName, ["name1"]) as cursor:
for row in cursor:
if row == 70 and row ==71 and row ==72:
row[0] = 'no land use'
cursor.updateRow(row)
print "Processing complete"
else:
print 'nothing founded'
but i get no result:
Answer
You must check the value of the OBJECTID field, not the row
object:
import arcpy
lyrName = r"G:\PROJECTS\herzel138\gis\layers\New File Geodatabase.gdb\digum2"
with arcpy.da.UpdateCursor(lyrName, ["name1", "OID@"]) as cursor:
for row in cursor:
if row[1] in (70, 71, 72):
row[0] = 'no land use'
cursor.updateRow(row)
print """Updated row {}""".format(row[1])
The OID@ token refers to the OBJECTID field, no matter how it's called (this may vary depending on the dataset format - file gdb, shapefile, enterprise gdb...). See the arcpy.da.UpdateCursor help page for reference.
No comments:
Post a Comment