rows1 = gp.UpdateCursor("PS_lyr")
searchRows = gp.searchcursor(fc): searchRow = searchRows.next() while searchRow: if searchRow.FIELDNAME == None: #or inverse of "... != None:" print "It's NULL!" searchRow = searchRows.next() del searchRow del searchRows
rows = gp.SearchCursor("PS_lyr") row = rows.next() try: while row: for i in range(0,numSchools): school = row.GetValue(Elem) M[1] = school M.sort(lambda x, y: cmp(x[1], y[1])) M.reverse() if M[0][1] > 0: school = M[0][0] row.SetValue("[ScenarioTemplate_1011." + String + "]", school) gp.AddMessage("You made it through the if statement") rows.UpdateRow(row) row = rows.next() except: gp.AddError("Failed to set the value of new scenario field to new school assignment")
******Could there be some kind of lock or permission on the FC in the personal geodatabase that is keeping the field SUBDIV from being updated?
I know the code works because I've ran it here and it updated the field "SUBDIV". I have to think it's something simplelike a misspelled field name (in the data or the code) or improper indenting or something like that.
I added in a few more print commands to see where the code is failing...it looks like the following code is not working for some reason.....maybe it doesn't like using a variable. Like earlier the code runs without any errors but it still doesn't change the name in the SUBDIV field in the FC....I'm stumped.row2.SUBDIV = p
OK, 1.) copy & paste my code2.) edit these 3 to match your mdb and file names:gp.Workspace = "C:/junk/temp.mdb"InputFC = "A"TAB = "B"3.) Let me know what happens.
Does your code look something like this (other than I changed the table names and mdb name so I would test here).This code works:import arcgisscripting gp = arcgisscripting.create() gp.Workspace = "C:/junk/temp.mdb" inputFC = "A" TAB = "B" #Table Loop cur1 = gp.SearchCursor(TAB) row1 = cur1.Next() while row1: #Get the values from the fields(tab) c = row1.GetValue("CATEGORY") s = row1.GetValue("SUBNO") p = row1.GetValue("PROJECT") print "\nc = "+str(c) print "s = "+str(s) print "p = "+str(p) #fc loop cur2 = gp.UpdateCursor(inputFC) row2 = cur2.Next() while row2: #Get the values from the fields(fc) t = row2.GetValue("Category") l = row2.GetValue("LISTNUM") n = row2.GetValue("SUBDIV") print "t = "+t print "l = "+l print "n = "+str(n) #Populate field in the fc based on a match if t == c and l == s: row2.SUBDIV = p #Execute the new value to the fc cur2.UpdateRow(row2) #fc next row2 = cur2.Next() #table next row1 = cur1.Next() del cur2 del cur1 print "\nDone. \n"
import arcgisscripting gp = arcgisscripting.create() gp.Workspace = "C:/junk/temp.mdb" inputFC = "A" TAB = "B" #Table Loop cur1 = gp.SearchCursor(TAB) row1 = cur1.Next() while row1: #Get the values from the fields(tab) c = row1.GetValue("CATEGORY") s = row1.GetValue("SUBNO") p = row1.GetValue("PROJECT") print "\nc = "+str(c) print "s = "+str(s) print "p = "+str(p) #fc loop cur2 = gp.UpdateCursor(inputFC) row2 = cur2.Next() while row2: #Get the values from the fields(fc) t = row2.GetValue("Category") l = row2.GetValue("LISTNUM") n = row2.GetValue("SUBDIV") print "t = "+t print "l = "+l print "n = "+str(n) #Populate field in the fc based on a match if t == c and l == s: row2.SUBDIV = p #Execute the new value to the fc cur2.UpdateRow(row2) #fc next row2 = cur2.Next() #table next row1 = cur1.Next() del cur2 del cur1 print "\nDone. \n"
Is it printing the word "Match" and not writing anything or is it not getting into the if statement at all?
Any ideas on why the new SUBDIV data does not show in the FC?
Tested this morning the code runs without any errors....however it doesn't replace the SUBDIV in the FC with the data from the table.#Populate field in the fc based on a match if t == c and l == s: print "Match" row2.SUBDIV = p #Execute the new value to the fc cur2.UpdateRow(row2) #fc next row2 = cur2.Next()
I think I see it, the cursor on your FC needs to be a UpdateCursor (not a SearchCursor).
What sort of error are you getting?
## Read the dbf and populate the shp. import arcgisscripting, sys, os gp = arcgisscripting.create() gp.workspace = os.getcwd() dbf = "Apr.dbf" shp = "Apr2009.shp" # dbf loop rows = gp.SearchCursor(dbf) row = rows.Next() while row: # Get the value from the field(dbf) value = row.GetValue("ID_NUM") print "Processing ID_NUM = "+str(value) # shp loop rows2 = gp.UpdateCursor(shp) row2 = rows2.Next() while row2: # Get the value from the field (shp) value2 = row2.GetValue("ID_NUM") # Populate field in shp based on a match if value2 < 1740: row2.city_legal = "Lower" if value2 > 1739: row2.city_legal = "Higher" # Execute the new value to the shp rows2.UpdateRow(row2) # shp next row2 = rows2.Next() # dbf next row = rows.Next() del rows2 del rows print "\nDone.\n"
import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) gp.OverWriteOutput = 1 FC = gp.GetParameterAsText(0) LEV2 = sys.argv[2] LEV1 = sys.argv[3] UpdateField = sys.argv[4] cur = gp.UpdateCursor(FC) row = cur.Next() A = [11,12,13,14,17,18,19] B = [15,16] C = [2] D = [3] E = [4] F = [5] G = [6] H = [7] I = [8] while row: if row.GetValue(LEV2) in A: row.SetValue(UpdateField,"Urban & Built-Up") if row.GetValue(LEV2) in B: row.SetValue(UpdateField,"Industrial & Mining") if row.GetValue(LEV1) in C: row.SetValue(UpdateField,"Agriculture") if row.GetValue(LEV1) in row.SetValue(UpdateField,"Rangeland") if row.GetValue(LEV1) in E: row.SetValue(UpdateField,"Upland Forest") if row.GetValue(LEV1) in F: row.SetValue(UpdateField,"Water") if row.GetValue(LEV1) in G: row.SetValue(UpdateField,"Wetlands") if row.GetValue(LEV1) in H: row.SetValue(UpdateField,"Barren Land") if row.GetValue(LEV1) in I: row.SetValue(UpdateField,"Trans, Comm, & Util") cur.UpdateRow(row) row = cur.Next() del cur
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.