1

I am trying to update the atrribute data of a feature class with respect to another one by matching a common field. But it is returning an error for the setValue command. My code looks like:

import arcpy fc="D:/Geonames_CA.gdb/Export_Output" fs="D:/abc.gdb/Export" rows = arcpy.SearchCursor(fc) fldList=arcpy.ListFields(fc) rws = arcpy.SearchCursor(fs) flList=arcpy.ListFields(fs) for row in rows: for fld in fldList: a = row.getValue("PLACE_NAME") a_xmin=row.getValue("XMIN") a_xmax=row.getValue("XMAX") a_ymin=row.getValue("YMIN") a_ymax=row.getValue("YMAX") for rw in rws: for fl in flList: b = row.getValue("PLACE_NAME") b_xmin=row.getValue("XMIN") b_xmax=row.getValue("XMAX") b_ymin=row.getValue("YMIN") b_ymax=row.getValue("YMAX") if b==a: cursor = arcpy.UpdateCursor(fs) for r in cursor: r.setValue(b_xmin, a_xmin) r.setValue(b_xmax, a_xmax) r.setValue(b_ymin, a_ymin) r.setValue(b_ymax, a_ymax) cursor.updateRow(r) del r, cursor 

I am only getting this error:

Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in main.dict File "D:\Script2.py", line 25, in r.setValue(b_xmin, a_xmin) File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 1007, in setValue return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.

2
  • Can you please format your code sample correctly so we can read it more easily? Commented Mar 6, 2014 at 12:45
  • I'm not sure why you are are iterating through fields with the "for fld in fldList:" line if you are specifying the fields manually in the lines below. The error is likely coming up because r.setValue(...) expects the field name as the first argument and you are giving it two values. Here is the documentation for rows:resources.arcgis.com/en/help/main/10.1/index.html#//… Commented Mar 6, 2014 at 13:59

1 Answer 1

1

Your code looks to do a lot of unnecessary things. For instance, you iterate over filed list, but never use variables fl or fld. So here is code that could do what you need from my understanding.

It first gather all the place_name variables and put it in a dictionary and after, iterate thought the second feature class and update the values.

import arcpy fc="D:/Geonames_CA.gdb/Export_Output" fs="D:/abc.gdb/Export" #Reading values rows = arcpy.SearchCursor(fc) dictValues={} for row in rows: a = row.getValue("PLACE_NAME") a_xmin=row.getValue("XMIN") a_xmax=row.getValue("XMAX") a_ymin=row.getValue("YMIN") a_ymax=row.getValue("YMAX") if not dictValues.has_key(a): dictValues[a]=(a_xmin,a_xmax,a_ymin,a_ymax) else: #Log error! arcpy.AddWarning("Duplicate PLACE_NAME in input: " + a ) del row, rows #Writing values cursor = arcpy.UpdateCursor(fs) for r in cursor: b=r.getValue("PLACE_NAME") if dictValues.has_key(b): r.setValue("XMIN", dictValues[b][0]) r.setValue("XMAX", dictValues[b][1]) r.setValue("YMIN", dictValues[b][2]) r.setValue("YMAX", dictValues[b][3]) cursor.updateRow(r) else: #Log error! arcpy.AddWarning("No PLACE_NAME " + b + " in input" ) del r,cursor del dictValues 

Hopes this helps you figure out your problem and understand more how arcpy and python works.

2
  • 1
    Pretty sure you also need cursor.updateRow(r) in there before you delete r and cursor. Commented Mar 6, 2014 at 14:38
  • Sure... I forgot! Corrected. Commented Mar 6, 2014 at 14:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.