query = ' "CONTOUR" = 5100'
# Script Name: contourindexcalc.py # Author: Stephen Gushue # Purpose: Find and calculate values of the contours to illustrate 10 foot contours # Import system modules import arcpy, sys, traceback from arcpy import env # Set workspace arcpy.env.workspace = 'U:\\GEO\\projects\\python' # Local Variables featureclass = 'contours_test.shp' fieldlist = arcpy.ListFields (featureclass) try: # Sets row hold query setfield = '"CONTOUR"%' query = 'setfield == 0' # Create a Search Cursor srows = arcpy.SearchCursor (featureclass, query) for srow in srows: # assign a variable for the value of srow.CONTOUR # assign a variable for the value of srow.INDEX_VALU contour = srow.CONTOUR index = srow.INDEX_VALU # Create Update Cursor urows = arcpy.UpdateCursor(featureclass, query) # Cycle through the rows # to actually update the row in the cursor # with the values obtained from the search cursor for urow in urows: urow.INDEX_VALU = "10 Foot Index" urows.updateRow(urow) print 'DONE' del urow, urows, srow, srows except: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n" msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n" arcpy.AddError(msgs) arcpy.AddError(pymsg) print msgs print pymsg
Solved! Go to Solution.
try: # Create Update Cursor urows = arcpy.UpdateCursor(featureclass) # Cycle through the rows # to actually update the row in the cursor # with the values obtained from the search cursor for urow in urows: contour = urow.CONTOUR if int(float(contour) / 10) == (float(contour) / 10): urow.INDEX_VALU = "10 Foot Index" urows.updateRow(urow) print 'DONE' del urow, urows
try: # Create Update Cursor urows = arcpy.UpdateCursor(featureclass) # Cycle through the rows # to actually update the row in the cursor # with the values obtained from the search cursor for urow in urows: contour = urow.CONTOUR if int(float(contour) / 10) == (float(contour) / 10): urow.INDEX_VALU = "10 Foot Index" urows.updateRow(urow) print 'DONE' del urow, urows