Thursday, 11 January 2018

arcgis 10.3 - Changing 1000 values in attribute table using ArcPy?


I work on a point layer which contains 2000 features. I'm trying to change all the values "industry" in field "name" only (it has 1000 features of industry values) into "landUse". The FID of the those features start from FID 500 til FID 1500 in running order.


In this code, continually to Change specific rows in attribute table using Arcpy in ArcGIS 10.3


import arcpy

lyrName = r"G:\PROJECTS\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])

I can change several rows, but I can't write 1000 number in the brackets.


How can I change those 1000 features values only using Arcpy?



Answer



You should either add a where clause in the cursor (recommended) or check the value of the name field when iterating the rows:



with arcpy.da.UpdateCursor(lyrName, ["name"], """name = 'industry'""") as cursor:
for row in cursor:
row[0] = 'landUse'
cursor.updateRow(row)

with arcpy.da.UpdateCursor(lyrName, ["name"]) as cursor:
for row in cursor:
if row[0] == 'industry':
row[0] = 'landUse'
cursor.updateRow(row)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...