Skip to main content
edited tags; edited tags
Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 353
edited tags
Link
Jason Bellino
  • 4.3k
  • 1
  • 28
  • 35
added 394 characters in body
Source Link
Nevu
  • 429
  • 1
  • 7
  • 12

This should be simple but I've spent days trying everything to get it to work. I need to update a field in a layer based on two other fields. I can't even get it to update based on one field. Could someone please tell me whats wrong. So in this script I want to be classifying the outfield as "poor" if the infield is "Sandy". I will also have another field of numbers (and infield2 = "10").

rows = arcpy.UpdateCursor(infc) #this is my feature layer for row in rows: if row.getValue(Infield1) == "Sandy": row.setValue(Outfield, "poor") else: row.setValue(Outfield, "none") rows.updateRow(row) del rows 

Thanks for all the answers. The script only works if written like this: I did not want to name the field names though, but at least it works. 

The problem with this script is the second valueonly way I could do a range 5 - 10 was to put > 5 and <10 (<10see line 23) sets the output all to "none". Probably because the number values in this field are things like 1, 6. 0-10 doesn't work either.

for row in rows:  = arcpy if row.UpdateCursorgetValue(infc"Texture")   == "Sandy" forand row.getValue("Humus") in< rows10: if  row.setValue("Richness", "poor") elif row.getValue("Texture") == "Sandy" and row.getValue("Humus") <=> "10"10: row.setValue("Richness", "poor""medium") elseelif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") < 5: row.setValue("Richness", "none""poor") rowselif row.updateRowgetValue("Texture") == "Sandy-Clay" and row.getValue("Humus") >= 5 and row.getValue("Humus") <= 10: del rows,  row.setValue("Richness", "medium") 

yet something like this works to update a field based on another field, without naming it.

rows = arcpy elif row.UpdateCursorgetValue(infc"Texture") == "Sandy-Clay" and row.getValue("Humus") > 10: for  row.setValue("Richness", in"rich")  rows elif row.getValue("Texture") == "Clay" and row.getValue("Humus") < 5: valrow.setValue("Richness", ="poor") elif row.getValue("Texture") == "Clay" and row.getValue(inputfield"Humus") > 5: row.setValue(outfld"Richness",val "rich") else:  row.setValue("Richness", "unclassified") rows.updateRow(row)  del rows, row 

This should be simple but I've spent days trying everything to get it to work. I need to update a field in a layer based on two other fields. I can't even get it to update based on one field. Could someone please tell me whats wrong. So in this script I want to be classifying the outfield as "poor" if the infield is "Sandy". I will also have another field of numbers (and infield2 = "10").

rows = arcpy.UpdateCursor(infc) #this is my feature layer for row in rows: if row.getValue(Infield1) == "Sandy": row.setValue(Outfield, "poor") else: row.setValue(Outfield, "none") rows.updateRow(row) del rows 

Thanks for all the answers. The script only works if written like this: I did not want to name the field names though. The problem with this script is the second value (<10) sets the output all to "none". Probably because the number values in this field are things like 1, 6. 0-10 doesn't work either.

rows = arcpy.UpdateCursor(infc)    for row in rows: if row.getValue("Texture") == "Sandy" and row.getValue("Humus") <= "10": row.setValue("Richness", "poor") else: row.setValue("Richness", "none") rows.updateRow(row) del rows, row 

yet something like this works to update a field based on another field, without naming it.

rows = arcpy.UpdateCursor(infc) for row in rows: val = row.getValue (inputfield) row.setValue(outfld,val) rows.updateRow(row)  del rows, row 

This should be simple but I've spent days trying everything to get it to work. I need to update a field in a layer based on two other fields. I can't even get it to update based on one field. Could someone please tell me whats wrong. So in this script I want to be classifying the outfield as "poor" if the infield is "Sandy". I will also have another field of numbers (and infield2 = "10").

rows = arcpy.UpdateCursor(infc) #this is my feature layer for row in rows: if row.getValue(Infield1) == "Sandy": row.setValue(Outfield, "poor") else: row.setValue(Outfield, "none") rows.updateRow(row) del rows 

Thanks for all the answers. The script only works if written like this: I did not want to name the field names though, but at least it works. 

The only way I could do a range 5 - 10 was to put > 5 and <10 (see line 23)

for row in rows:   if row.getValue("Texture") == "Sandy" and row.getValue("Humus") < 10:   row.setValue("Richness", "poor") elif row.getValue("Texture") == "Sandy" and row.getValue("Humus") > 10: row.setValue("Richness", "medium") elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") < 5: row.setValue("Richness", "poor") elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") >= 5 and row.getValue("Humus") <= 10:   row.setValue("Richness", "medium")  elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") > 10:   row.setValue("Richness", "rich")   elif row.getValue("Texture") == "Clay" and row.getValue("Humus") < 5: row.setValue("Richness", "poor") elif row.getValue("Texture") == "Clay" and row.getValue("Humus") > 5: row.setValue("Richness", "rich") else:  row.setValue("Richness", "unclassified") rows.updateRow(row) del rows, row 
added 217 characters in body
Source Link
Nevu
  • 429
  • 1
  • 7
  • 12
Loading
added 2 characters in body
Source Link
Nevu
  • 429
  • 1
  • 7
  • 12
Loading
added 375 characters in body
Source Link
Nevu
  • 429
  • 1
  • 7
  • 12
Loading
Tweeted twitter.com/#!/StackGIS/status/118671673787551745
edited title
Link
underdark
  • 85k
  • 22
  • 238
  • 419
Loading
Source Link
Nevu
  • 429
  • 1
  • 7
  • 12
Loading