Accessing Shape field for point feature class through UpdateCursor causes crash

594
2
03-30-2011 06:06 AM
AndyGarcia
New Contributor
I am attemping to snap points in a feature class to their nearest points on a line feature.  See the code mentioned here: http://blog.rtwilson.com/how-to-snap-points-to-lines-in-arcgis-with-python/ I've been playing with this code in ArcGIS 10.0 with Windows 7 Enterprise 64 bit using the Python window where all the data is in a geodatabase.

My problem is when the script gets to the iterative use of UpdateCursor to access the point feature to iteratively update the shape (with the new point), I get an error in execution. When I moved to trying to move through the loop I found that the code failed when trying to update the actual Shape field.

In an attempt to debug this, I tried to manually access the point feature's shape object:

# updated each point using a cursor
rows = arcpy.UpdateCursor( inputFeature, "", "", "NEAR_X, NEAR_Y" )
row = rows.next()

# attempt to access point object
p = arcpy.getValue("Shape")


The last line will always crash ArcMap.

I have attempted the following:
1. Check geometry
2. Repair geometry
3. Tried moving the cursor forward 6-7 times to make sure it wasn't a specific feature in the class that had the problem.

None of these have yielded any result, attempts to access the Shape field programatically still cause ArcMap to crash.

Where do I go next?
0 Kudos
2 Replies
AndyGarcia
New Contributor
I found the problem (which was two-fold).

First I was setting the x and y members of the new Point class, not the X and Y.

Second, the script I referenced used row.shape = p to change the shape, while I was using row.setValue( "Shape", p). In my case, this caused a crash because Shape was not part of the UpdateCursor field, so I added Shape as a field. This now executes as expected.

Why not a better error message when attempting to set a field via an UpdateCursor where the field was not selected?

Why the difference between Point.x/Point.y and Point.X/Point.Y?
0 Kudos
by Anonymous User
Not applicable
Andy
I wanted to pass along a very big "Thank You" for posting this fix. I have spent an embarrassing amount of time tracking down this error. I forgot to add Shape as a field for my update cursor as well. I know I never would have figured that out on my own.

Dan
0 Kudos