0

Continually to

Changing 1000 values in attribute table using ArcPy?

Change specific rows in attribute table using Arcpy in ArcGIS 10.3

I try to change 850 different values in attribute table of point layer into value "red use" (the total features in this layer is 1300).

I need to change FID start from 300 til FID 1150 and using this code:

import arcpy

lyrName = r"G:\desktop\Project\lyr\point1.shp"
with arcpy.da.UpdateCursor(lyrName, ["name", "FID"]) as cursor:
    for row in cursor:
        if row[1] in (0, 1, 2):
            row[0] = 'no land use'
            cursor.updateRow(row)
            print """Updated row {}""".format(row[1])

Line number 6 is the rows that should be changed. I understand that row

 if row[1] in (0, 1, 2):

should be change- but i don't how. How can i changed those 850 row with python code, based on FID field?

3

Make use of the OID@ token available with data access cursors. It can be used in place of the FID field name for the feature class.

import arcpy

lyrName = r"G:\desktop\Project\lyr\point1.shp"
with arcpy.da.UpdateCursor(lyrName, ["name", "OID@"]) as cursor:
    for name, oid in cursor:
        if oid >= 300 and oid < 1150:
            row = ("no land use", oid)
            curs.updateRow (row)
  • Emil, your code works after i changed the last row into: cursor.updateRow (row) thanks. – newGIS Jan 7 '18 at 7:20

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.