1

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?

3

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)
  • So, you cannot select features using the name attribute? You want to assign an 'industry' value to a range of features based on their ID? – GISGe Jan 4 '18 at 12:24
  • if you can select features using the 'industry' value, no need to select based on the objectid – GISGe Jan 4 '18 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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