Skip to main content
added 3 characters in body
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor:

import arcpy

# The input FC
fc = "C:/W/Sik.gdb/yourFC"

with arcpy.da.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor:
    for row in cursor:
        # row[0] = "aspect"
        # row[1] = "aspect_m60"
        if row[0] < 60:
            row[1] = (row[0] - 60) + 360
        elif row[0] == 60:
            row[1] = row[0] - 60
        else:
            row[1] = row[0] - 60

        cursor.updateRow(row)

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor:

import arcpy

# The input FC
fc = "C:/W/Sik.gdb/yourFC"

with arcpy.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor:
    for row in cursor:
        # row[0] = "aspect"
        # row[1] = "aspect_m60"
        if row[0] < 60:
            row[1] = (row[0] - 60) + 360
        elif row[0] == 60:
            row[1] = row[0] - 60
        else:
            row[1] = row[0] - 60

        cursor.updateRow(row)

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor:

import arcpy

# The input FC
fc = "C:/W/Sik.gdb/yourFC"

with arcpy.da.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor:
    for row in cursor:
        # row[0] = "aspect"
        # row[1] = "aspect_m60"
        if row[0] < 60:
            row[1] = (row[0] - 60) + 360
        elif row[0] == 60:
            row[1] = row[0] - 60
        else:
            row[1] = row[0] - 60

        cursor.updateRow(row)
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor:

import arcpy

# The input FC
fc = "C:/W/Sik.gdb/yourFC"

with arcpy.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor:
    for row in cursor:
        # row[0] = "aspect"
        # row[1] = "aspect_m60"
        if row[0] < 60:
            row[1] = (row[0] - 60) + 360
        elif row[0] == 60:
            row[1] = row[0] - 60
        else:
            row[1] = row[0] - 60

        cursor.updateRow(row)