AnsweredAssumed Answered

How to pair SearchCursor with UpdateCursor

Question asked by deleted-user-MS0lE1F_0-sy on Mar 13, 2015
Latest reply on Mar 13, 2015 by dkwiens

I am having a little trouble figuring out where I am going wrong.


If I have "NW" in my direction field I want to move the point a certain distance, but if it is "NE"  I want the move to be opposite.  I think I am almost there but it will only take my last Update for all the features.


import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

arcpy.env.overwriteOutput = True

fc = arcpy.GetParameterAsText(0)

NWxOffset = 200
NWyOffset = 200

NExOffset = -220
NEyOffset = -200

search = arcpy.SearchCursor(fc)
value = ""
for row in search:
    value = row.getValue("direction")
    with arcpy.da.UpdateCursor(fc, ["SHAPE@XY"]) as cursor:
        if value == "NW":
            for row in cursor:
                cursor.updateRow([[row[0][0] + NWxOffset, row[0][1] + NWyOffset]])
        elif value == "NE":
            for row in cursor:
                cursor.updateRow([[row[0][0] + NExOffset, row[0][1] + NEyOffset]])