Python, Arc10 - copy shape field contents from one table to another.

2450
14
11-17-2010 04:39 AM
JohnSanders
Emerging Contributor
This is just a read from one table (shapefile) and a write to another table (shapefile).
This would work in 9.3.1 (SP1, SP2) but no longer in 10, with or without SP1:

>>> copyShape = Arow.shape
>>> arrayShape = copyShape.getPart( )
>>> Crow.setValue( 'Shape', arrayShape )     # or Crow.shape = arrayShape

error is:
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\arcobjects.py", line 941, in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.

This is a polyline shape.  Arow is a searchCursor, Crow is an insertCursor.
type(arrayShape) gives: <class 'arcpy.arcobjects.arcobjects.Array'>, and it looks to be populated OK.

I also have a point copy I'm getting ready to test, so if there is a separate fix for that you might know of, I'd appreciate mention of that, too.

Thanks.
0 Kudos
14 Replies
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Hello John,

I am researching on data integration issues and use cases, especially in feature matching and conflation areas. It seems you are trying to unite multiple source centerlines with inconsistent attributes into one, which could be a challenging task, as you have already experienced. I wonder if your datasets cover similar areas or meet along the data borders and how the attribute situations are. Is it possible for you to send some sample data to me? My email address is dlee@esri.com.

Thanks!
0 Kudos
JohnSanders
Emerging Contributor
In going back to 9.3.1, I've discovered that I may have created the insert cursor from a Table View instead of the shape file.  In 9.3.1, all fields, with the exception of the Shape field, will write with either the table-view derived cursor or a shape-file derived cursor.  In 9.3.1, Shape can only be written with an Insert Cursor that was derived from the shape-file.

So I suspect the problem in 10 may have only been a poor combination of using/not using .getPart( ) and the wrong Insert Cursor.

None, some, or all of the above may be accurate.  There needs to be a "donkey" icon.
0 Kudos
JacobBlair
Deactivated User
Ye gods, I was about to pipe in with my own similar problem, but with getValue.  I kept poking though, and found what the problem is.  Your suspicion of using a table view is probably correct, since the behavior that replicates that error is: running row.getValue(field) or row.setValue(field) when the given field doesn't exist in the row (e.g. SHAPE in a table view).

Since my getValue is in a Python class I use for many purposes my solution was to wrap the getValue with an exception handler for a RuntimeError, making sure getValue was the only code in the try clause that would do throw one of those.

In the original post's case, you'd want something like this:

try:
    Crow.setValue( 'Shape', arrayShape )
except RuntimeError:
    # This means setValue failed, i.e. 'Shape' is not a valid field name in Crow.
    # Put what you want script to do in this case here.
    pass


-Jacob Blair
0 Kudos
JohnSanders
Emerging Contributor
Jacob,

Thanks for posting your experience with this problem.  You did not specifically say, but I'm assuming that you are on Arc10.  Your input is giving me the confidence to re-install 10.

I'm going to use your suggestion of using the "try", "except".  I should be able to additionally trap bad geometries that way and not have to run a separate scan of the shapefile.

Thanks again,

John Sanders
0 Kudos
JacobBlair
Deactivated User
John,
  Yes, I'm using v10 now.  A quick check with the legacy 9.3 'gp' shows that it will throw the RunTimeError in that situation as well.

-Jacob
0 Kudos